Click here to Skip to main content
15,917,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team.
I have data like below format.



<span id="1" dnd-draggable="{value:'a',text:'apple'}" />
<span id="2" dnd-draggable="{value:'b',text:'bat'}" />


here i want to get 'span' tag based on 'value' in dnd-draggable attribute using Jquery

for example:

if i give 'a', i will get first 'span' tag.




Thanks
Nanda Kishore.CH
Posted
Updated 20-Jan-16 1:59am
v2

Here is a list of all the jQuery selectors. Selectors | jQuery API Documentation[^]
 
Share this answer
 
Try with below code:
HTML
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
	$("button").click(function(){

		$("span").each(function(){
			var newObject = JSON.parse($(this).attr("dnd-draggable"));
			if(newObject.value == "a")
			{
				alert("True");
			}
			else
			{
				alert("False");
			}
		});
	});
});
</script>
</head>
<body>

<h2>This is a heading</h2>

<span id="1" dnd-draggable='{"value":"a","text":"apple"}' />
<span id="2" dnd-draggable='{"value":"b","text":"bat"}' />

<button>Click me</button>

</body>
</html>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900