benjo benjo - 1 year ago 65
jQuery Question

check if <font> html tag has color and add label | js | jq

I have this HTML:

<font color="#ff0000">מתחנת חוף הכרמל</font>

I want to check if it has the
style and if it does I want to add a
to it. This is what I tried to do with no success:

if ($("font").css('color') == '#ff0000' ) {
} else {
console.log('not working');

Any advice? If it's possible also with pure JS it will be great.

Answer Source

try this:

<font style="color:#ff0000;">מתחנת חוף הכרמל</font>

var col = document.getElementsByTagName('font')[0].style.color;
 if(col=='rgb\(255, 0, 0\)') {
 } else {
   console.log('do stuff...');

check the fiddle for it:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download