Reputation: 1165
I made a code in which I am trying to add the quantity of the product when a user types in the quantity he.she wants for that product. the problem is I am not able to select the anchor
via jquery to get the href
link so that I can add new value to it.
My code:
$('.mival').keyup(function(event) {
var i=$(this).parents(".cart").next('.milink').attr('href');
alert(i);
});
When I try to alert it says undefined
My Markup of html:
<div class="cart">
<div><strong>Price:</strong> <span>$20.30</span></div>
<div><strong> Qty:</strong><span>
<input type="text" class="mival" value="1" />
</span></div>
<a class="milink" href="http://example.com/vid=3">Add to Cart </a> </div>
I have not yet written the code for adding the value to the link I can do that. the problem is how to get value from this markup's a
element so that I can get the href
link .
Upvotes: 3
Views: 2115
Reputation: 388316
You also have a missing >
at the end of <div class="container"
.
$(this).closest(".container").children('a.milink')
ex:
$('.mival').keyup(function(event) {
var i = $(this).closest(".container").children('a.milink').attr('href');
alert(i);
});
Demo: Fiddle
Upvotes: 2