Home > Web Front-end > JS Tutorial > Detailed explanation of jQuery dynamically removing and adding background images

Detailed explanation of jQuery dynamically removing and adding background images

小云云
Release: 2018-01-23 11:25:43
Original
2845 people have browsed it

This article mainly introduces jQuery's method of dynamically removing and adding background images, and analyzes jQuery's dynamic operation skills for page element styles and event responses in the form of examples. Friends who need it can refer to it. I hope it can help everyone.

Use jQuery to remove and add images

1, Style


<style type="text/css">
  .changeImage{
     background:url(images/right.png) no-repeat center;
  }
</style>
Copy after login

2, JS

(1) When changing the style of the label, you need to remove the previously added style


$("#tab tr").find("td").removeClass("changeImage");
Copy after login

(2) Add the style


$("#tab tr").find("td").addClass("changeImage");
Copy after login

Attachment: Complete example demo:






jQuery移除和添加图片


<script>
function removeimg(){
$(&quot;#tab tr&quot;).find(&quot;td&quot;).removeClass(&quot;changeImage&quot;);
}
function addimg(){
$(&quot;#tab tr&quot;).find(&quot;td&quot;).addClass(&quot;changeImage&quot;);
}
</script>


  
制造商型号说明价值
1997FordE350"ac abs moon"3000.00
1999Chevy"Venture ""Extended Edition"""""4900.00
1999Chevy"Venture ""Extended Edition Very Large"""""5000.00
1996JeepGrand Cherokee"MUST SELL!
air moon roof loaded"4799.00
Copy after login

Related recommendations:

Use css to add background to elements of unknown width and height Image method

How to add a background image in a php file

css strange usage of IMG to add a background image to match the display effect is stunning_html/css_WEB -ITnose

The above is the detailed content of Detailed explanation of jQuery dynamically removing and adding background images. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template