i am trying to use a jquery selector. There are 10 divs in my page. each div has a submit button which has attribute called post and its value varies from 1 to 10. so when first submit button is clicked i want to alert the h1 in the first div. So I tried this

<script>
$(document).ready(function() {
	$('.submit').click(function() {
		var post = $(this).attr("post");
		alert(post);
		post = "div#"+post+" h1";
		alert(post);
		var name = $(post).value();
		alert(name);


		
	});
	
});

but the actual value of post is not being passed even though being a javascript variable.

Some notes: post is not a valid attribute. If the button and h1 share a parent or "ancestor", you can use siblings() or closest() and find() to find the h1. Otherwise, you can use html5 and data-post instead. Furthermore, h1s don't have a value, use html() or text() instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.