user198989
user198989

Reputation: 4665

Change children font color on click?

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>

enter image description here

Upvotes: 0

Views: 279

Answers (3)

miibpa
miibpa

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

user3521271
user3521271

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

Satpal
Satpal

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

Related Questions