I’ve got an onclick event which is calling a function, passing the current div:
<div onclick="deleteline($(this));">
In my deleteline function, how do I get a child of the parent of $(this) where the name contains Qty?
In this example I’m looking to get the ProdQty input box:
<div>
<input id="PrdQty" type="hidden" value="1">
<div onclick="deleteline($(this));">
</div>
EDIT:
This page is getting included multiple times within another page via an ajax call.
Therefore if I assign the clickable div an ID, it’s going to cause a conflict after this code is injected into the parent for the 2nd time.
As a result, I’ve used the suggestions below, kept the inline onclick and I’m getting the qty using: sender.parent().find(‘input[id*=”Qty”]’)
You can use CSS selectors for this in jQuery (http://api.jquery.com/category/selectors/)
So your example would be:
That will return all the inputs at the same level as $(this) which have ‘Qty’ in their id as an array. If you only want the first one add .first() onto the end of the line, ie: