-1

I am trying to fire a :click(); function but unable to do that I don't know why but when I type the :alert(); function in start then my code works I am stuck in this situation.

I search over internet but no success.Any help from you is very appreciable.

HTML:

<div class="edit-options-dated">
    <span><?php echo date('H:i:m', (time()-strtotime($note->getCreationDatetime()))); ?></span>         
    <ul class="pull-right edit-task-icons">
        <li class="delete-task"><i class="fa fa-trash-o"></i></li>
        <li class="edit-task"><i class="fa fa-pencil"></i></li>
        <li class="setting-task"><i class="fa fa-cog"></i></li>
    </ul>
    <ul class="settings-task-options">
        <h3>note groups</h3>    
        <li><a href="#">new</a></li>
        <li><a href="#">Affiliate Tasks</a></li>
        <li><a href="#">next week</a></li>
    </ul>
</div> 

JQuery:

$(window).load(function() {

// alert('ok');

$('li.setting-task').on('click', function() {

    $(this).parent().parent().find('.settings-task-options').toggle();

});

$('li.delete-task').click(function() {

    $('.delete-2').slideDown();

});

});
qarar
  • 33
  • 1
  • 9

2 Answers2

2

instead of $(window).load(); you can use

$(document).ready(function(){
    // code here
});

or

$(function(){
  //code here
});

may be you need to Event binding on dynamically created elements?

$(document).ready(function(){

// alert('ok');

 $('body').on('click','li.setting-task', function() {

      $(this).parent().parent().find('.settings-task-options').toggle();

  });

  $('body').on('click','li.delete-task',function() {

    $('.delete-2').slideDown();

  });

});
Community
  • 1
  • 1
Mohamed-Yousef
  • 22,772
  • 3
  • 17
  • 27
1

You can try this...

$(function(){ // shorthand for document ready - document is safely loaded
    $(document.body).on('click', 'li.setting-task' ,function(e){
      $(this).parent().parent().find('.settings-task-options').toggle();
    });
  });

JQuery on - info here

document.body basically search the body part of your document for select element and makes event for it
JTC
  • 2,975
  • 3
  • 26
  • 43