Reputation: 4665
I'm trying to change font color on click, but unfortunetely it doesnt change. What is the correct way to do it ?
$("#hepsi").click(function(){
$(this).removeClass('boskolon2').addClass('boskolon').siblings('.boskolon').removeClass('boskolon').addClass('boskolon2');
$(this).children("img").not("img.profimg").hide();
$(this).children("font").css({color: 'red'});
});
html
<div id="hepsi" class="boskolon2">
<img class="profimg" src="misal.png" width=36 \><div>
<b><font id="probas">AkifFF</font></b><br>22, Mersin</div>
</div>
Upvotes: 0
Views: 279
Reputation: 235
I think that the font tag is not supported in html 5, so I'd use CSS instead font tag, you can use this:
$(this).children("b").css({color: 'red'});
and remove font tag.
Cheers
Upvotes: 1
Reputation: 36
use toggleClass, when you want to change a color, or some css rule dont do it with js, is slower than css
$("#hepsi").click(function(){
$(this).toggleClass('myColor');
});
css code
.bosklon {
color: ...;
}
.bosklon.myColor{
color : ...;
}
html
<div id="hepsi" class="bosklon">
<img class="profimg" src="misal.png" width=36 \><div>
<b><font id="probas">AkifFF</font></b><br>22, Mersin</div>
</div>
Upvotes: 1
Reputation: 133403
Use .find()
instead of .children()
, note .children()
only travels a single level down the DOM tree.
$(this).find("font").css({"color": 'red'});
Upvotes: 1