Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Wednesday 1 April 2015

Introduction
In this article I will explain how to delete multiple divs with same id or class using jQuery. By using remove() function of jQuery we can delete or remove multiple divs with same class name.
In this article I have deleted divs with same class name “delete”. I have placed five divs on the webpage. Out of five, four has same class name. I will delete these divs using remove() method of jquery.

Method we used to delete multiple Divs With same Class Name:
<script type="text/javascript">
    $(function () {
        $('#btnDelete').click(function () {
            $('.delete').remove();
        });
    })
</script>

Full Source Code for aSample Application:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery delete multile divs with single id</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnDelete').click(function () {
            $('.delete').remove();
        });
    })
</script>
</head>
<body>

 <fieldset style="width:300px">
            <legend><strong>Delete Multiple Div with Same class</strong></legend>
<div id="div1">
Div 1: No class Name
</div>
<div id="div2" class="delete">
Div2: With class Name "Delete"
</div>
<div id="div3" class="delete">
Div3:  With class Name "Delete"
</div>
<div id="div4" class="delete">
Div4 : With class Name "Delete"
</div>
<div id="div5" class="delete">
Div5 : With class Name "Delete"
</div><br />
<input type="button" id="btnDelete" value="Delete multiple Div" /></fieldset>
</body>

</html>
Categories: , ,

0 comments:

Post a Comment