You can do it like Braziliam way, we call it as “Gambiarra”
$('input [type=submit]').click(function(){
var productname = $(this).parent().find('.post-meta-ab a').html();
});
PS. If you cant set a UNIQUE ID for your DOM elements, don’t use any at all.
Basically for each product on you list you have this structure:
<li class="ms-tt grid_3" data-id="id-1" data-type="digital">
<div class="m-thumb entry-image hover-content">
<a href="#"><img src="images/jewellery-tools/casting-soldering1/14.jpg" alt="Flasks Stainless Steel Perforated C-16"></a>
<div class="image-overlay">
<div class="buttons-tt clearfix">
<a class="permalink" href="#"><i class="icon-link"></i></a>
<a class="zoom" href="images/jewellery-tools/casting-soldering1/14.jpg" data-gal="photo[portfolio]" title="Flasks Stainless Steel Perforated C-16"><i class="icon-resize-full"></i></a>
</div>
</div>
</div>
<p class="post-meta-ab"><span><a href="#">Flasks Stainless Steel Perforated C-16</a></span><br />
<span>Details: Flasks Stainless Steel Perforated For Casting 3" Dia X 5",6" & 7"</span><br />
<span><i class="icon-circle"></i>Shipping Weight: 750gms</span><br /><span><i class="icon-circle"></i>Price: € 17.00</span><br />
<span><i class="icon-circle"></i>Quantity: <input type="text" style="width:20px" maxlength="100" name="a1" id="a1" />
<input type="submit" value="Add" style="margin-top:-8px" class="btn btn-danger" name="asubmit" id="a1sub" /></span></p>
</li>
Inside your <li>
element you have your button and you have a <p>
with your product title, and you <p>
have a “post-meta-ab” class.
So when you say:
$('input [type=submit]').click(function(){ //here you'r saying, "when any input submit get clicked execute the code above"
var productname = $(this).parent().find('.post-meta-ab a').html(); // here you are saying, $(this) means the input submit clicked, and parent() means your <li>, and finally you tell to look for any element with the post-meta-ab class and look for the a inside it.
});
Understand now?
8
solved Hundreds of buttons in one page with same name and same ids, how to differentiate?