JS modifies the class attribute in HTML __c language

Source: Internet
Author: User

Using JS to modify the HTML class attribute value, summed up under:

First, get the class attribute value

var value = $ ("div"). attr ("class")//Here Gets the class attribute value
var array=val.split ("");//separate the class value by a space, and get each value through the array
var value = document.getElementById ("div"). ClassName;

Change the value of class attribute

document.getElementById ("tr"). ClassName = "Styleclass";//styleclass for the new property value
document.getElementById ("tr"). SetAttribute ("Class", "Styleclass");

Third, add a class attribute (on the original basis)

var obj = document.getElementById (' A1 ');
Obj.classname + = ' styleclass '; Note that the preceding space prevents two properties from being combined

Four, remove a class attribute

$ ("tr"). Removeclass ("Styleclass");


1. Determine if there are attributes in the class attribute:

if (Value.indexof ("Styleclass") >= 0) {}

2. Change the border of select through CSS

<span style= "border:1px solid #7FFF00; Position:absolute; Overflow:hidden ">
<select style=" margin:-1px "> 
    <option >bbb</option> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.