html - how to remove the background image using jquery with class name -
I am trying to remove background image using jquery. But this is not happening, but the same format I can change this by using the background color
& lt; Html & gt; & Lt; Top & gt; & Lt; Style & gt; H1 {background-image: url ('paper.gif'); Background color: #cccccc; } & Lt; / Style & gt; & Lt; Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script & gt; $ (Document) .ready (function () {$ ("h1"). Each (function (index) {$ ("." + $ (This) .attr ("class")). CSS ('background-image ',' No one ');});}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; H1 class = "red" & gt; This is a title & lt; / H1> & Lt; H1 class = "yellow" & gt; This is a title & lt; / H1> & Lt; H1 class = "red" & gt; This is a title & lt; / H1> & Lt; / Html & gt;
You do not need class part, try it:
< Script> gt; pre & lt; $ (Document) .ready (function () {$ ("h1"). CSS ({'background-image', 'none'});}; & Lt; / Script & gt;
In jQuery, you are not modifying the stylesheet, you are modifying the DOM after the stylesheet, so attack the element directly.
Comments
Post a Comment