Vladimir Potapov
Vladimir Potapov

Reputation: 2437

How to change span text than in the parent element

I'm using double click on the img

This code

$("#insert-zone").on("dblclick", ">div>img", function(){
 console.log($(this).parentNode.className(spanDefCat));

 var answer = confirm ("Set Defaul Cat to " +$("#txt_CategoryID").val()+"?")
    if (answer){....

.

This is the div item

<div class="item-container cart-item sameCat">
   <div class="SetDefault">
      <img border="0" title="Carrie Style Silver Name Necklace" src="medium_101-01-071-02.jpg" alt="1102">
      <div class="item-header">
         <div class="item-body">
            <ul class="item-ul">
               <li>
                  <span class="spanDefCat">DefaultCat: 32</span>
               </li>
            </ul>
         </div>
      </div>
      <div class="item-footer"></div>
</div>

When I double click the img, I need to go back to parent cart-item than contains li with span class spanDefCat like you see it in code and change the DefaulCat to 80 or what ever I need to change the span.

full Html

    <div class="ui-widget-content">
    <ol id="insert-zone" class="ui-droppable ui-sortable">
    <div class="item-container cart-item sameCat">
    <div class="item-container cart-item ">
    <div class="item-container cart-item sameCat">
    <div class="item-container cart-item sameCat">
   </ol>
    </div>

Upvotes: 0

Views: 292

Answers (3)

reggaemahn
reggaemahn

Reputation: 6648

Here is the code that does what you want:

$(function(){
    $("img").dblclick(function(){
        $(this).parent().find(".spanDefCat").each(function(){
            $(this).text("DefaultCat: 80");
        });
    });
});

Here is the working fiddle: http://jsfiddle.net/ZrA8E/

Upvotes: 0

Jayamurugan
Jayamurugan

Reputation: 1825

Add this code inside .on function

var newCatVal = "DefaultCat: "+$("#txt_CategoryID").val();
$(this).closest('.cart-item').find(".spanDefCat").text(newCatVal);

Upvotes: 0

Daniel Kurz
Daniel Kurz

Reputation: 816

you can use $(this).parent().find('.spanDefCat').html($("#txt_CategoryID").val())

This will change the value of all .spanDefCat in the parent of the image.

Upvotes: 1

Related Questions