[RESOLVED] how to click the appended li ?-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] how to click the appended li ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Resolved [RESOLVED] how to click the appended li ?

    hi
    i want to click the appended <li>

    i append a <li> into <ul>

    and now i want to click them but it's don't work fine

    here is my append code JQ :
    Code:
    $('li').append($('<p>').text(post.w_name).attr('name','post_'+post.w_id).attr('id','post_'+post.w_id).addClass('f_ok'));
    and here my html code :

    Code:
    <ul dir="rtl">
        <li><h1>Online</h1></li>
    </ul>

    i want to do this :
    Code:
                $('li p').click(function(){
                    alert($(this).text())
                });
    it's don't work with me help

    and thanks
    My SySteM : INtel COre 2 DU, GiGaByte Motherboard, 4 GB RAM, 2 TB HDD, Nvidia 9800 GT 1 GB, 19.5" TFT(Wide), Discovery SySteM Daah


    Dim MyPost As Boolean

    If MyPost = True Then
    Debug.Print "⇐ Click Rate this post ! To Rate It "
    Elseif MyPost = False Then
    Debug.Print "Ask For More Help "
    Endif

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,500

    Re: how to click the appended li ?

    When you assign a callback function using .click(function(){}), it can only be assigned to currently-existing DOM elements. If your append() is occurring after the assignment, it won't work that way.

    There are at least two ways of dealing with this. One is to use the .on() function, which can assign callbacks for elements that will exist in the future. The other approach is to specifically attach the callback to your <p> element when you're creating it:
    Code:
    var newPara = $('<p></p>');
    newPara.text(post.w_name)
    	.attr('name','post_'+post.w_id)
    	.attr('id','post_'+post.w_id)
    	.addClass('f_ok')
    	.click(function(){
    		alert($(this).text())
    	});
    $('li').append(newPara);
    This is a good approach if you want the callback to be assigned specifically to just that element.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Re: how to click the appended li ?

    thanks for helping me
    My SySteM : INtel COre 2 DU, GiGaByte Motherboard, 4 GB RAM, 2 TB HDD, Nvidia 9800 GT 1 GB, 19.5" TFT(Wide), Discovery SySteM Daah


    Dim MyPost As Boolean

    If MyPost = True Then
    Debug.Print "⇐ Click Rate this post ! To Rate It "
    Elseif MyPost = False Then
    Debug.Print "Ask For More Help "
    Endif

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.