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

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>


Statement
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

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor