• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » An Easy Way To Remove Attribute In HTML Element Using JQuery

An Easy Way To Remove Attribute In HTML Element Using JQuery

By Sigit Prasetya Nugroho ∙ August 30, 2019 ∙ Javascript ∙ Leave a Comment

Share : TwitterFacebookTelegramWhatsapp

JQuery has a built-in method that used to delete attribute of elements. This method named removeAttr(). Not only for a single attribute, but JQuery remove attr method also delete many of attributes from the selected element.

The use of removeattr() method is quite easy. You only need to add the attribute’s name that you want to delete in the removeAttr() parameter.

Table of Contents

  • 1 removeAttr() Syntax
  • 2 Delete attribute in JQuery with removeAttr() Method
    • 2.1 1. Delete a single attribute
    • 2.2 2. Removes many attributes
    • 2.3 3. JQuery Remove Disabled Attribute
  • 3 Conclusion

removeAttr() Syntax

1
$(selector).removeAttr(attribute)

Explanation:

selector: the selected HTML elements (can be filled with the class attribute, id attribute,…)

Related Articles :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • How To Use JQuery Input File / Upload File Change Event
  • How to Make a Shake Effect Validation Like the WordPress Login Form

Attribute: The attribute’s name to be deleted. To delete the multiple attributes from the selected elements, please separate them with space.

Delete attribute in JQuery with removeAttr() Method

1. Delete a single attribute

1
2
3
4
5
6
7
8
9
10
<a style="color:red" href="#" title="this title will remove soon">Click to remove title attribute</a>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(){
let a = $(this).removeAttr("title");
console.log(a);
})
})
</script>

2. Removes many attributes

1
2
3
4
5
6
7
8
9
10
<a style="color:red" href="#" title="this title will remove soon">Click to remove title attribute</a>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(){
let a = $(this).removeAttr("title href style");
console.log(a);
})
})
</script>

Example Remove Attribute Jquery

3. JQuery Remove Disabled Attribute

To enabled/disabled attribute using JQuery, you can use the prop() method. With RemoveAttr, we can also replace the use of the prop() method to activate the element.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<input id="txtinput" value="test input" />
<hr>
<button class="btn-prop-disabled">Prop Disabled</button> <button class="btn-prop-enabled">Prop Enabled</button> <button class="btn-remove">Remove Attr</button>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".btn-prop-disabled").click(function(){
$("#txtinput").prop("disabled",true)
})
 
$(".btn-prop-enabled").click(function(){
$("#txtinput").prop("disabled",false)
})
$(".btn-remove").click(function(){
$("#txtinput").removeAttr("disabled")
})
})
</script>

Remove Disabled Atribut With Removeattr Jquery

Another tutorial : Tutorial Javascript DOM HTML (Include 14 Example) : Easy To Understand

Conclusion

RemoveAttr() is the same as the removeAttribute() method in javascript. The difference is that using JQuery will shorten the time and code’s writing.

Another Javascript Related Post :

  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS
  • How To Implement Login Page And Protected Route ReactJS
  • Complete Tutorial React Router Dom For Beginners (Easy-To-Understand)
  • The Right Way Understanding React Lifecycle For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com