I want to change the class of a td tag given the td tag's id:
<td id="td_id" class="change_me"> ...
I want to be able to do this while inside the click event of some other dom object. How do I grab the td's id and change its class?
I want to change the class of a td tag given the td tag's id:
<td id="td_id" class="change_me"> ...
I want to be able to do this while inside the click event of some other dom object. How do I grab the td's id and change its class?
change class using jquery
try this
$('#selector_id').attr('class','new class');
you can also set any attribute using this query
$('#selector_id').attr('Attribute Name','Attribute Value');
Here is the solution using jQuery:
$(document).ready(function(){
if($('#td_id').hasClass('change_me')) {
$('#td_id').removeClass('change_me').addClass('something_else');
}
});
I better use the .prop to change the className and it worked perfectly:
$(#td_id).prop('className','newClass');
for this line of code you just have to change the name of newClass, and of course the id of the element, in the next exemple : idelementinyourpage
$(#idelementinyourpage).prop('className','newClass');
By the way, when you want to search which style is applied to any element, you just click F12 on your browser when your page is shown, and then select in the tab of DOM Explorer, the element you want to see. In Styles you now can see what styles are applied to your element and from which class its reading.