search
HomeWeb Front-endJS TutorialHow jquery changes the style of html tags (two implementation methods)_jquery

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:

 

jq sets and gets the attributes of the tag
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
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
macOS:如何更改桌面小部件的颜色macOS:如何更改桌面小部件的颜色Oct 07, 2023 am 08:17 AM

在macOSSonoma中,小部件不必隐藏在屏幕外,也不必像在以前版本的Apple的macOS中那样在通知中心面板中被遗忘。相反,它们可以直接放置在Mac的桌面上&#8211;它们也是交互式的。不使用时,macOS桌面小部件会采用单色样式淡入背景,从而减少干扰,并允许您专注于活动应用程序或窗口中手头的任务。但是,当您单击桌面时,它们将恢复为全彩色。如果您更喜欢单调的外观,并且希望在桌面上保留这一方面的统一性,那么有一种方法可以使其永久化。以下步骤演示了它是如何完成的。打开“系统设置”应用

如何在Go语言中使用正则表达式提取HTML标签内容如何在Go语言中使用正则表达式提取HTML标签内容Jul 14, 2023 pm 01:18 PM

如何在Go语言中使用正则表达式提取HTML标签内容导读:正则表达式是一种强大的文本匹配工具,它在Go语言中也有着广泛的应用。在处理HTML标签的场景中,正则表达式可以帮助我们快速提取需要的内容。本文将介绍如何在Go语言中使用正则表达式提取HTML标签的内容,并给出相关代码示例。一、引入相关包首先,我们需要导入相关的包:regexp和fmt。regexp包提供

如何使用Python正则表达式去除HTML标签如何使用Python正则表达式去除HTML标签Jun 22, 2023 am 08:44 AM

HTML(HyperTextMarkupLanguage)是用于创建Web页面的标准语言,它使用标签和属性来描述页面上的各种元素,例如文本、图像、表格和链接等等。但是,在处理HTML文本时,很难将其中的文本内容快速地提取出来用于后续的处理。这时,我们可以使用Python中的正则表达式来去除HTML标签,以达到快速提取纯文本的目的。在Python中,正则表

WordPress网页错位现象解决攻略WordPress网页错位现象解决攻略Mar 05, 2024 pm 01:12 PM

WordPress网页错位现象解决攻略在WordPress网站开发中,有时候我们会遇到网页元素错位的情况,这可能是由于不同设备上的屏幕尺寸、浏览器兼容性或者CSS样式设置不当所致。要解决这种错位现象,我们需要仔细分析问题、查找可能的原因,并逐步进行调试和修复。本文将分享一些常见的WordPress网页错位问题以及相应的解决攻略,同时提供具体的代码示例,帮助开

CSS网页背景图设计:创建各种背景图样式和效果CSS网页背景图设计:创建各种背景图样式和效果Nov 18, 2023 am 08:38 AM

CSS网页背景图设计:创建各种背景图样式和效果,需要具体代码示例摘要:在网页设计中,背景图是一种重要的视觉元素,它可以有效地增强页面的吸引力和可读性。本文将介绍一些常见的CSS背景图设计样式和效果,并提供相应的代码示例。读者可以根据自己的需求和喜好来选择和应用这些背景图样式和效果,以达到更好的视觉效果和用户体验。关键词:CSS,背景图,设计样式,效果,代码示

PHP如何去除字符串中的HTML标签?PHP如何去除字符串中的HTML标签?Mar 23, 2024 pm 09:03 PM

PHP是一种常用的服务器端脚本语言,广泛应用于网站开发和后端应用程序开发中。在开发网站或应用程序时,经常会遇到需要处理字符串中的HTML标签的情况。本文将介绍如何使用PHP去除字符串中的HTML标签,并提供具体的代码示例。为什么需要去除HTML标签?在处理用户输入或从数据库中获取的文本时,经常会包含HTML标签。有时候我们希望在显示文本时去除这些HTML标签

php中怎么转义html标签php中怎么转义html标签Feb 24, 2021 pm 06:00 PM

在PHP中,可以使用htmlentities()函数来转义html,能把字符转换为HTML实体,语法“htmlentities(string,flags,character-set,double_encode)”。PHP中也可以使用html_entity_decode()函数来反转义html,把HTML实体转换为字符。

如何在Java中从给定的字符串中删除HTML标签?如何在Java中从给定的字符串中删除HTML标签?Aug 29, 2023 pm 06:05 PM

String是Java中的final类,它是不可变的,这意味着我们不能改变对象本身,但我们可以更改对象的引用。可以使用String类的replaceAll()方法从给定字符串中删除HTML标签。我们可以使用正则表达式从给定字符串中删除HTML标记。从字符串中删除HTML标签后,它将返回一个字符串作为普通文本。语法publicStringreplaceAll(Stringregex,Stringreplacement)示例publicclassRemoveHTMLTagsTest{&nbs

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft