Home Web Front-end JS Tutorial How jquery changes the style of html tags (two implementation methods)_jquery

How jquery changes the style of html tags (two implementation methods)_jquery

May 16, 2016 pm 05:43 PM
html tag style

As for how to modify html tags, for js, you can set the attributes of the tag through setAttribute and get the attributes of the tag through getAttribute. Of course, similar functions can also be achieved in jq. The method is definitely much simpler than js. .
Change its style by modifying the label attributes
js sets and gets the attributes of the label

Copy code The code is as follows:

 


It is worth noting that the content of JS’s window.onload method block is executed after JQ’s $(function(){}) method block After that, execute again.
Two change the style of the label by modifying its css style
Look at the basic syntax:
Copy code The code is as follows:

$("#attr").addClass("banner");//Add style
$("#attr").removeClass( "banner");//Remove style
         //JQ supports joint writing, because the return result of removeClass is also a Jq object, so all methods and events of the Jq object can be used
$("#attr ").removeClass("banner").addClass("bannerOver");

The following is an example of highlighting the current dd block when clicking on the dd label
Copy code The code is as follows:


<script> <br>$(function () { <br>$('#menu_title').find('dd').click(function () { <br>$('#menu_title').find('dd').removeClass('cur'); <br>$(this).addClass('cur'); <br>}) <br>}) <br></script>


The following is the interlaced color change effect for the table
Copy the code The code is as follows:

.odd { background: #808080; }
.even { background: #ffd800; }
.selected { background: #0094ff; color: #fff; }  .hover { background: #808080; }

Copy code The code is as follows:

var $trs = $("# menu_title>dd"); //Select all rows $trs.filter(":odd").addClass("odd"); //Add odd style to odd rows $trs.filter(":even").addClass( "even"); //Add odd style to even-numbered rows

After clicking the row, let the current row be highlighted
Copy code The code is as follows:

//Click on the row to add a color change style
$trs.click(function(e) {
$(this). addClass("selected")
   .siblings()    .removeClass("selected");
})

Add mouse move-in and move-out events
Copy code The code is as follows:

    // Mouse Moving in and out
$("#menu_title>dd").hover(
function () {
$(this).addClass("hover");
},
function ( ) {
$(this).removeClass("hover");
}
);

Well, let’s talk about the style control of tags. Here it goes, thank you for reading!
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)

macOS: How to change the color of desktop widgets macOS: How to change the color of desktop widgets Oct 07, 2023 am 08:17 AM

In macOS Sonoma, widgets don't have to be hidden off-screen or forgotten in the Notification Center panel like they did in previous versions of Apple's macOS. Instead, they can be placed directly on your Mac’s desktop – they’re also interactive. When not in use, macOS desktop widgets fade into the background in a monochrome style, reducing distractions and allowing you to focus on the task at hand in the active application or window. However, when you click on the desktop, they return to full color. If you prefer a drab look and want to retain that aspect of uniformity on your desktop, there's a way to make it permanent. The following steps demonstrate how it is done. Open the System Settings app

How to extract HTML tag content using regular expressions in Go language How to extract HTML tag content using regular expressions in Go language Jul 14, 2023 pm 01:18 PM

How to use regular expressions to extract HTML tag content in Go language Introduction: Regular expression is a powerful text matching tool, and it is also widely used in Go language. In the scenario of processing HTML tags, regular expressions can help us quickly extract the required content. This article will introduce how to use regular expressions to extract the content of HTML tags in Go language, and give relevant code examples. 1. Introduce related packages First, we need to import related packages: regexp and fmt. regexp package provides

How to remove HTML tags using Python regular expressions How to remove HTML tags using Python regular expressions Jun 22, 2023 am 08:44 AM

HTML (HyperTextMarkupLanguage) is a standard language for creating Web pages. It uses tags and attributes to describe various elements on the page, such as text, images, tables, links, etc. However, when processing HTML text, it is difficult to quickly extract the text content for subsequent processing. At this time, we can use regular expressions in Python to remove HTML tags to quickly extract plain text. In Python, regular tables

How to remove HTML tags from string in PHP? How to remove HTML tags from string in PHP? Mar 23, 2024 pm 09:03 PM

PHP is a commonly used server-side scripting language that is widely used in website development and back-end application development. When developing a website or application, you often encounter situations where you need to process HTML tags in strings. This article will introduce how to use PHP to remove HTML tags from strings and provide specific code examples. Why do you need to remove HTML tags? HTML tags are often included when processing user input or text obtained from a database. Sometimes we want to remove these HTML tags when displaying text

Guide to solving misalignment of WordPress web pages Guide to solving misalignment of WordPress web pages Mar 05, 2024 pm 01:12 PM

Guide to solving misaligned WordPress web pages In WordPress website development, sometimes we encounter web page elements that are misaligned. This may be due to screen sizes on different devices, browser compatibility, or improper CSS style settings. To solve this misalignment, we need to carefully analyze the problem, find possible causes, and debug and repair it step by step. This article will share some common WordPress web page misalignment problems and corresponding solutions, and provide specific code examples to help develop

CSS web background image design: create various background image styles and effects CSS web background image design: create various background image styles and effects Nov 18, 2023 am 08:38 AM

CSS web page background image design: Create various background image styles and effects, specific code examples are required Summary: In web design, background images are an important visual element, which can effectively enhance the attractiveness and readability of the page. This article will introduce some common CSS background image design styles and effects, and provide corresponding code examples. Readers can select and apply these background image styles and effects according to their own needs and preferences to achieve better visual effects and user experience. Keywords: CSS, background image, design style, effect, code representation

How to escape html tags in php How to escape html tags in php Feb 24, 2021 pm 06:00 PM

In PHP, you can use the htmlentities() function to escape html, which can convert characters into HTML entities. The syntax is "htmlentities(string,flags,character-set,double_encode)". You can also use the html_entity_decode() function in PHP to de-escape html and convert HTML entities into characters.

How to remove HTML tags from given string in Java? How to remove HTML tags from given string in Java? Aug 29, 2023 pm 06:05 PM

String is a final class in Java, it is immutable, which means we cannot change the object itself, but we can change the reference of the object. HTML tags can be removed from a given string using the replaceAll() method of String class. We can remove HTML tags from a given string using regular expressions. After removing the HTML tags from the string, it returns a string as normal text. Syntax publicStringreplaceAll(Stringregex,Stringreplacement) example publicclassRemoveHTMLTagsTest{&nbs

See all articles