I’m currently using the following method to return a value from a div:
<div data-post-id="1">
<a>Add To Favourites</a>
<div>
$(this).parent().data('post-id');
What I would like to do is something like this:
<div>
<input type="hidden" name="postId" value="1" />
<a>Add To Favourites</a>
<div>
Keep in mind:
-
There will be several posts on each page. Each div containing a post will have it’s own input.
-
The value of the postId will not be accessible from my JS file. So the its reference has to be retrieved via JavaScript somehow.
I want to get away from using parent() and use a single reference for each post’s id, regardless whether the action is to favourite, send to a friend, etc…
to get the val of postId use