JQuery addClass, removeClass and toggleClass methods, jquerytoggleclass

Source: Internet
Author: User
Tags jquery addclass

JQuery addClass, removeClass and toggleClass methods, jquerytoggleclass

The addClass, removeClass, and toggleClass methods of jQuery can replace the first two methods in some cases.

The first method addClass adds a class to the element.

The second method, removeClass, removes a class.

The third method toggleClass is a mutex class.

 

<input id="Text1" type="text"  />

 

Create a style. When the text box is focused, the border of the text box is highlighted and widened. When blur is used, the original style is restored.

.textbborder {        border:solid;        border-color:red;        border-width:3px;    }

 

You can use the jQuery code to implement the following:


In the above Code, Insus. NET is implemented using addClass and removeClass methods. If you use the toggleClass method, refer to the following code:

 

$ (Function () {// $ ('# Text1 '). focus (function () {// $ (this ). addClass ('textbborder'); //}); // $ ('# text1 '). blur (function () {// $ (this ). removeClass ('textbborder'); //}); $ ('# text1 '). focus (function () {$ (this ). toggleClass ('textbborder') ;}; $ ('# text1 '). blur (function () {$ (this ). toggleClass ('textbborder ');});})Source Code


Demo:

 

Related Article

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.