fiticida fiticida - 2 months ago 8
jQuery Question

Change color from checkbox text

<P><INPUT TYPE="checkbox" NAME="nombre" VALUE="Si"> bla bla <BR></P>


This is my code, and I want to change the color from the text
bla bla
. What I have done is
$("p").css('color','red');
but the problem is that if I add some next text using the
before()
or
after()
jQuery methods it also obtains the red color. Any ideas how I can avoid this?

Answer

Add wrapper span or div whatever suits you for "bla bla". Actually $("p").css('color','red'); will assign color property on entire

element

HTML

<P><INPUT TYPE="checkbox" NAME="nombre" VALUE="Si">
<span class="demo-class">bla bla<span> <BR></P>

Jquery

$("p .demo-class").css('color','red');