Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove attribute of HTML tag

Is it possible to remove the attribute of the first HTML <div> tag? So, this:

<div style="display: none; ">aaa</div>

becomes

<div>aaa</div>

from the following:

<div style="display: none; ">aaa</div>
<a href="#" style="display: none; ">(bbb)</a>
<span style="display: none; ">ccc</span>​
like image 323
DGT Avatar asked Oct 11 '10 20:10

DGT


People also ask

What is delete attribute used for?

When an attribute is deleted, it is removed from any related products and attribute sets. System attributes are part of the core functionality of your store and cannot be deleted. Before deleting an attribute, make sure that it is not currently used by any product in your catalog.

How do you remove an item in HTML?

Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.

How do I delete a class attribute?

removeAttr() method. With jQuery, you can use the . removeAttr() method to remove the class attribute from an element. It is equivalent to the JavaScript's removeAttribute() method.

What are the 3 types of attribute in HTML?

HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes: Usually the required and optional attributes modify specific HTML elements.


2 Answers

Or pure JavaScript:

document.getElementById('id?').removeAttribute('attribute?')
like image 94
Phoenix Avatar answered Sep 21 '22 05:09

Phoenix


To remvove it from literally the first element use .removeAttr():

$(":first").removeAttr("style");

or in this case .show() will show the element by removing the display property:

$(":first").show();

Though you probably want to narrow it down to inside something else, for example:

$("#container :first").removeAttr("style");

If you want to show the first hidden one, use :hidden as your selector:

$(":hidden:first").show();
like image 34
Nick Craver Avatar answered Sep 24 '22 05:09

Nick Craver