[Solved] Accessing a tags value in JQuery [closed]


First of all your html structure is invalid, the starting and ending of tags are not proper:

<a> tag and <figure> tag are not closing properly, so have a look into it and correct html first

I am posting answer by changing some html:

$('.addBasket').click(function(){
  // here we have used .siblings as we need to get text of same level element
  var basketProduct = $(this).siblings('.PTitle').text(); // use .text() for getting text inside any element
  alert(basketProduct)
  $('<li>').text(basketProduct).appendTo('.BasketBar');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<div class="product">
  <figure class="col-sm-3" height="220" id="product" >
    <p class="PTitle"> <strong>Stylish Table and Chairs Set</strong></p>
    <img src="GardenFurnitureImages/small.jpg"/>
    <p style="display: inline" class="price"> Price: £499 </p>
    <input style="display: inline" type="button" value="Add to Basket" class="addBasket">
  </figure>
</div>

0

solved Accessing a

tags value in JQuery [closed]