css - Why is this jQuery code not working to alter background-color in Firefox? -
I'm trying to get a hang of jQuery and I had a code of this simple bit that refuses to work It has also come to know why this can not work?
& lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" src = "jquery.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("div"). Live ("click", divclicked);}); Css ("background color", "red");} & lt; / script & gt; divclicked function (if ($ (this) .css ("background color") == "lightblue") $ (this) ;; Style type = "Text / CSS"> Div {background color: lightbu;} gt; body & gt; & lt; div Id = "testdiv" & gt; This is a test & lt; / div & gt; & lt; / body & gt; & lt; / html & gt; Thanks in advance.
Update: The solution below to use "background color" instead of "background-color", when style is inline If you use a stylesheet.
I have updated the example to use a stylesheet I
backgroundcolor from "post-text" itemprop = "text"> background color to your script:
($ (This) .css ("backgroundcolor") == "lightblue") $ (this) .css ("backgroundcolor", "red");
DOM Dash names To avoid using them because they are not valid JavaScript identifiers.
Hey! Paolo removed his answer, while I was writing a comment on this ... I did not know that .css ("background color" for ") anything Useful, very little real RGB value back! In your case, the effect is the same (since your reasoning is basically the original value needed), but it is still worth noting for future reference.
< P> Apart from: If you are competent to rely on CSS class Read and use the style directly, you will have a much easier time - jQuery plays very well with CSS sections, offers easy methods, and them.
Comments
Post a Comment