Home php教程 PHP开发 Jquery css function to dynamically manipulate the style of DOM nodes

Jquery css function to dynamically manipulate the style of DOM nodes

Nov 24, 2016 am 09:36 AM

The css function in JQuery can set effects for DOM nodes. CSS functions generally have the following uses:
1. Determine whether an object is hidden:

$("#id").css("display")=="none " ;
Second, set the value of a style attribute in all matching elements:
$("div").css("color","#FF0000");
Three, put a "name/value pair" Object set to the style properties of all matching elements. This is the best way to set a large number of style
attributes on all matching elements:
$("div").css({ color: "#ff0000", background: "blue" });
If the attribute name If it contains "-", you must use quotation marks:
$("div").css({ "margin-left": "10px", "background-color": "blue" });
Here are some of what I wrote demo code.

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <meta name="author" content="LuisZhang"> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title></title> 
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script> 
    <script type="text/javascript"> 
        $(function() { 
            // $("div").click(function() { alert($(this).next("div").text()); }); 
            // $("div").click(function() { alert($(this).nextAll("div").text()); }); 
            // $("div").click(function() { $.each($(this).nextAll("div"), function() { $(this).css("background", "red") }); }); 
             
            $("p").click(function() { $.each($(this).nextAll("p"), function() { $(this).css("background", "#abccdd") }); }); 
            $("div").click(function() { $.each($(this).next("div"), function() { $(this).css({ "margin-left": "10px", color: "#abccdd", background: "blue" }) }); }); 
            $("#fristDiv").click(function() { $.each($(this), function() { $(this).css({ "margin-left": "10px", color: "#abccdd", background: "blue" }) }); }); 
            $("#lastDiv").click(function() { $.each($(this), function() { $(this).css({ "margin-left": "10px", color: "#abccdd", background: "blue" }) }); }); 
        }); 
    </script> 
</head> 
<body> 
<div id="fristDiv">aa</div> 
<div>bb</div> 
<div>cc</div> 
<div>dd</div> 
<p>p1</p> 
<p>p2</p> 
<p>p3</p> 
<p>p4</p> 
<div id="lastDiv">ee</div> 
</body> 
</html>
Copy after login


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)