I’m iterating over a div using :
Can I access a hidden parameter in this div within the iteration ?
<DIV>
<div id="myDiv" <input type="hidden" name="Language" value="English"> />
</DIV>
$('#myDiv div.id').each(function() {
//access a hidden parameter of the current div here
});
You can use one of the following methods:
The first
parameter = $(this).attr('data-hidden-parameter')requires the following structure:Whereas the latter works with getting/setting with the
data()method of jQuery:If you mean retrieving text, or other content/attributes, from a hidden element that’s a child of the
div.idelement, with mark-up such as:You could retrieve that value with:
Note your jQuery selector implies you’re iterating over a number of elements, based on the class of those elements, while your class-name,
id, implies you’re trying, instead, to search based on theidof an element. This might be pseudo-code to demonstrate your approach, but please don’t use a class-name ofid. It’s perfectly valid, but it’s terribly confusing. Albeit this is simply my own, personal, objection and response.Edited, to supply a more targeted answer, by amending one of the above suggestions with an appropriate selector:
References:
attr().data().find().:hiddenselector.text().val().