jquery - Another javascript undefined issue -
i'm having issue getting script run. it's close keeps throwing undefined error anytime add button object.
here html:
<div class="centerboxcontentsfeatured centeredcontent ie_margin" style="width:33%;"><div class="product-col"> <div class="tie"> <div class="indent2"> <div> <a class="name" href="http://localhost:8080/rfs700/index.php?main_page=product_info&cpath=37&products_id=128">tb-0070 tabletop interpreter booth</a> </div> <div class="img"> <a href="http://localhost:8080/rfs700/index.php?main_page=product_info&cpath=37&products_id=128"><img src="images/products/tb0070.jpg" alt="tb-0070 tabletop interpreter booth" title=" tb-0070 tabletop interpreter booth " width="130" height="130"></a> </div> <div class="desc"> tb-0070 tabletop interpreter booth accommodate... </div> <div class="price"><strong><img src="includes/templates/template_default/images/call_for_prices.jpg" alt="call price" title=" call price " width="78" height="20"></strong></div> <div class="buttons"> <a href="http://localhost:8080/rfs700/index.php?main_page=products_new&action=buy_now&products_id=128"><img src="includes/templates/theme324/buttons/english/button_in_cart.gif" alt="add cart" title=" add cart " width="106" height="27"></a><a href="http://localhost:8080/rfs700/index.php?main_page=product_info&cpath=37&products_id=128"><img src="includes/templates/theme324/buttons/english/button_goto_prod_details.gif" alt="go product's detailed information" title=" go product's detailed information " width="58" height="27"></a> </div> </div> </div> </div></div> here javascript code:
<script type="text/javascript"> $(document).ready(function () { var doc = $(".centerboxcontentsfeatured .price"); doc.each(function (){ var image = $(this).find("img").attr("alt"); var button = $(this).find(".buttons"); if (image == "call price"){ alert(button.find("a:first-child").attr("href")); } }); }); </script> when alert(button) displays object. if add else button object example shown in javascript code above, displays undefined. ideas?
$(".centerboxcontentsfeatured .price") not contain .buttons. need traverse 1 level doc back.
<script type="text/javascript"> $(document).ready(function () { var doc = $(".centerboxcontentsfeatured .price"); doc.each(function (){ var image = $(this).find("img").attr("alt"); var button = $(this).parent().find(".buttons"); if (image == "call price"){ alert(button.find("a:first-child").attr("href")); } }); }); </script>
Comments
Post a Comment