Loading ...

How to get all ids of div tags in particular div | CodeAsp.Net

How to get all ids of div tags in particular div

 /5
0 (0votes)

In this blog I will explain how to get all ids of div tags in particular div ,means to get all controls id in a particular element. I have used map method of jQuery. Below is the code snippet for it:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
	<div id="MainDiv">
		<div id="ChildDiv1">
			ChildDiv1</div>
		<div id="ChildDiv2">
			ChildDiv2</div>
		<div id="ChildDiv3">
			ChildDiv3</div>
		<div id="ChildDiv4">
			ChildDiv4</div>
	</div>
</body>
<script type="text/javascript">
	$(function()
	{
		var $childDivIds = $("#MainDiv").children().map(function(i, childDivId)
		{
			return childDivId.id;
		});
		$childDivIds.each(function(i, childDivId)
		{
			alert(childDivId);
		});

	});

</script>
</html>





So above we discussed how to get all controls ids in a particular div. We can use the above logic to find controls in other elements also like p(paragraph) tag etc.

Do let me know your feedback,comments.

Comments (no comments yet)

Top Posts