Remove id attribute from an element using jquery

72 Views

Remove id attribute from an element using jquery

Jquery | Remove id attribute from an element

The removeAttr() function from jquery is used to removes one or more attributes from the selected elements.

$("div").removeAttr("id");

 


 

Here seen an example with complete code

In this example, the id of div gets remove at the time of page load.

 <!DOCTYPE html>
<html lang="en">

<head>
    <title>Jquery | Remove id attribue from an element</title>
    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    <!-- Script to remove the Id attribue from div -->
    <script>
    $(document).ready(function() {
        $("div").removeAttr("id"); 
    });
    </script>
</head>

<body>
    <div id="first">
        <h1>This div ID removed after page load </h1>
    </div>
</body>

</html>