简体   繁体   中英

After a javascript function call anchor tag stop working

I am using a javascript function this function holds ajax request . and i also have a anchor tag. when page loads-a list of items shown and a button add new item appears

1.when i click on and item then it shows item detail.
2.then i click on add new buttom and form to add item shown.
3.but when i again click on any item it works fine but after that add 
new item stop working.

javascript function:

function Detail(ths,e){
    $(ths).siblings().removeClass('active');
        $(ths).addClass('active');
    var id = $(ths).attr('id');
        storage.setItem('itemId',id);

if(!e.target)
    {
    var top = $(ths).position().top;
    $('.list').scrollTop(top-100);      
}

    if(!$(e.target).hasClass('action'))
    {
      $.ajax({
        url : "manage-details.php",
        type: "POST",
        data: {id:id} ,
        success: function(text) {          
             $("#rightsec").html(text);   
        }
      })
    }
}

anchor code:

    <a title="Add Items" id="additems" class="" href="#!manage-items.php|add-items.php">
       <span >
       </span>
       <span >Add Items</span>
    </a>

above both codes describe the whole condition.

Items added after ajax are not binded with JQuery events, you have to bind them like this:

$( "body" ).on( "click", "h2", function() {
    // Do something
});

Doc here :) http://api.jquery.com/on/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM