Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Wednesday 1 April 2015

In this article I will explain how to use jquery to get all child div ids inside of parent div using map() function. By using jquery map() function we can get all child ids inside of another div.   

Sometime while working in asp.net and jquery it is needed to find the child div from parent div. This can be done easily by using map() method of Jquery. By using map function we can get all div ids from parent div in jquery.

Implementation of Map() Method in Jquery:

<script type="text/javascript">
    $(function () {
        $('#btnGet').click(function () {
            $('#pdiv > div').map(function () {
                alert(this.id);
            });
        });
    })
</script>

Full source Code for Sample Application:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get All Child Divs from Parent Div in jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnGet').click(function () {
            $('#pdiv > div').map(function () {
                alert(this.id);
            });
        });
    })
</script>
</head>
<body>
<center>
<fieldset style="width:300px">
    <legend><strong>Get Child Divs from Parent Div in jQuery</strong></legend>
<div id="pdiv">
<br />
<div id="div1">Div1: Find Div 1</div>
<div id="div2">Div2: Find Div 2</div>
<div id="div3">Div3: Find Div 3</div>
</div>
<br />
<input type="button" id="btnGet" value="Get Inside Div Ids" /></fieldset></center>
</body>

</html>
Categories: , ,

0 comments:

Post a Comment