I have a little issue.
I want to highlight the answer when you click on it but the .style
seem not working :(
I have a part of html code like this:
<div id="answers-type1">
<ol>
<img src="" id="answer-a-img" /><li id="answer-a" ></li>
<img src="" id="answer-b-img" /><li id="answer-b" ></li>
<img src="" id="answer-c-img" /><li id="answer-c" ></li>
<img src="" id="answer-d-img" /><li id="answer-d" ></li>
</ol>
</div>
and in my script i got this:
$("#answers-type1 li").click(function() {
$(this).style = "background-color: #FFFF00;";
if ($(this).text() == goodAnswer)
{
alert("JAYJAY");
}
else
{
alert("pas JAYJAY");
}
});
the function is well called on each click but the background is not changing i don't understand why :/
I looked over internet and saw a lot of people doing like that
thanks for answers
I have a little issue.
I want to highlight the answer when you click on it but the .style
seem not working :(
I have a part of html code like this:
<div id="answers-type1">
<ol>
<img src="" id="answer-a-img" /><li id="answer-a" ></li>
<img src="" id="answer-b-img" /><li id="answer-b" ></li>
<img src="" id="answer-c-img" /><li id="answer-c" ></li>
<img src="" id="answer-d-img" /><li id="answer-d" ></li>
</ol>
</div>
and in my script i got this:
$("#answers-type1 li").click(function() {
$(this).style = "background-color: #FFFF00;";
if ($(this).text() == goodAnswer)
{
alert("JAYJAY");
}
else
{
alert("pas JAYJAY");
}
});
the function is well called on each click but the background is not changing i don't understand why :/
I looked over internet and saw a lot of people doing like that
thanks for answers
Share edited May 24, 2012 at 17:14 James Allardice 166k22 gold badges334 silver badges315 bronze badges asked May 24, 2012 at 15:51 John SmithJohn Smith 1,1721 gold badge12 silver badges31 bronze badges4 Answers
Reset to default 2Use this
$(this).css("background-color","#FFFF00");
instead of this
this.style = "background-color: #FFFF00;";
The style is not applied because jQuery objects don't have a style
property. You can use the css
method instead:
$(this).css("background-color","#FFFF00");
Alternatively, you could use the underlying element (don't pass it to jQuery):
this.style.backgroundColor = "#FFFF00";
The second example will likely be more efficient.
Fixed here: http://jsfiddle/RichardTowers/99Zpz/
try:
$(this).css("background-color","#FFFF00");
instead of :
$(this).style = "background-color: #FFFF00;";
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745062030a4609021.html
评论列表(0条)