I need to remove a class from all table cells when an element's parent has a particular ID.
$(".closethis").click(function(){
var $this = $(this).parent().parent();
if ($this.attr("id") == "mainArea") {
$("#myTbl").removeClass("myClass");
}
});
I do need to check for ID because this is part of a function and if ID is not equal to this value it is probably for another case.
Looks right but it does not seem to work. Am I missing something?
Approach 2: First, we will use document. getElementById() to get the ID and store the ID into a variable. Then use JSON. stringify() method on the element (variable that store ID) and compare the element with 'null' string and then identify whether the element exists or not.
If you're trying to check the value of the ID property then you can get it using the attr method. Show activity on this post. // element could be any html element but inputs have val and div, spans and suchlike don't have val var Submit_Status = $('element'). attr('id') == 'Reset' ?
Hmm.. Ok.. $var looks like PHP.. i'd just call it was it is. Also, you have #. in your myTbl which means id and class.... so it depends on how you are identifying the cells.. but assuming the cells are td's inside a table ID'd "myTbl", try this
$(".closethis").click(function(){
var checkDiv = $(this).parent().parent();
if (checkDiv.attr("id") == "mainArea") {
$("#myTbl").find('td').removeClass("myClass");
}
});
If you can't make that work, give us the ID's or class's of each element and we can give you the correct code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With