find nearest td inside element [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Here's my code,
<script>
$(document).ready(function(){
$(".mail").on("click",function(){
alert($(this).closest('tr').find('.td_class div').attr('var'));
});
});
</script>
<table><tr>
<td class='td_class'><div var='value'></div></td>
<td><div class='mail'>click</div></td>
</tr>
<tr><td> </td></tr></table>
okay, I wanna alert 'value' that is div's attribute var...
but it's not working help me...
thank you.

in this particular case
var x = $(this).parent().prev().find('>div').attr('var');
alert(x);

You missed quotes for find(.td_class div)
<script>
$(document).ready(function(){
$(".mail").on("click",function(){
alert($(this).closest('tr').find('.td_class div').attr('var'));
});
});
</script>

Related

How do you call a prompt on page load with jquery? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I cant seem to figure it out. This is what I have so far:
<head>
<script src="jquery-3.5.1.min.js"></script>
var gamerName
<script>
$(document).ready(function(){
gamerName = prompt("Please enter your name."," ");
});
</script>
</head>
Keep the var assignment inside the script tag! Otherwise it will be parsed as HTML.
Minimal example;
let gamerName;
$(document).ready(function(){
gamerName = prompt("Please enter your name."," ");
console.log(gamerName);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

jQuery: how to add eventListener to whole document/Webpage [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
How do I add an eventListener to whole document with jQuery?
$("document").click(function (){
$("h1").css('color', 'red');
})
I want the h1 to change color if clicked anywhere in the document/webpage. Thanks!
Just remove the double quotations in the $("document") line
$(document).click(function (){
$("h1").css('color', 'red');
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Hello</h1>
just using "body" in quotation marks as following also works.
$("body").click(function (){
$("h1").css('color', 'red');
})

JavaScript Expanding Divs not working Correctly for me [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
https://jsfiddle.net/alachgar/upezxLas/3/
Hello All,
My Javascript that was working fine earlier now is Broken.. it worked for me just yesterday.. now it is the HOUSING Section Part works fine...
However Starting the Second Section in Light Blue it's Broken... I am not sure what I am missing..!
Please help. Thanks a alot.
Ed-
<script>
function showRent (rent_box)
{
var rent_chboxs =
document.querySelectorAll('[name="rent_eval1"],
[name="rent_eval2"],
[name="rent_eval3"],[name="rent_eval4"],[name="rent_eval5"],
[name="own_concerns"],
[name="address_different"]');
var vis = "none";
for(var i=0;i<rent_chboxs.length;i++) {
if(rent_chboxs[i].checked){
vis = "block";
break;
}
}
document.getElementById(rent_box).style.display = vis;
}
</script>
You just need to change the onclick Event name from showOwn to showRent in from line 78 to line 90 in your HTMl file
'showOwn' is not defined.
Or change it to showRent may work.

How to add a class to <TD> within a <TR>? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I need help with adding a class to a td element.
Currently, my tr has an id.
<tr id = "blah"><td>1234</td><td>5678</td></tr>
I would like to add a class to both td tags. Which I desire:
<tr id = "blah"><td class = "blink">1234</td><td class = "blink">5678</td></tr>
I had tried to use .addClass("blink");
with a $(blah.td).addClass("blink"); for instance but it did not work.
Two notes here,: I am planning to add the classes with the use of jQuery, and I would avoid giving each <td> in the row an id so that my codes doesn't get too fuzzy.
Selector should be $('.blah td')
$('.blah td').addClass('blink')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr class="blah"><td>1234</td><td>5678</td></tr>
</table>

What is causing my jQuery functions not run? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I can't figure out why the jQuery functions will not work with the html here
JS Fiddle: http://jsfiddle.net/JonaTheApprentice/E89rg/
function addItem() {
$('#list').append('<li><input type="checkbox" /> item</li>');
}
function removeItem() {
$('#list').children().filter(function () {
return this.firstChild.checked;
}).remove();
}
I don't see an element with id="list", that's what #list refers to.
I think you mean #items-listed. Changing that, and it works
I would get the value from the input id. I would also assign a click event for cleaner coding. Here is an example of your fiddle adding an item. Removing an item is just the reversal.
DEMO http://jsfiddle.net/E89rg/5/
$('#Enter').click(function(){
var Val = $('#item').val();
$('#items-listed').append('<li><input type="checkbox" />'+Val+'</li>');
});

Categories

Resources