0

I made a modal with help of jquery Json and this is main html

              <div id="photo_preview" style="display:none">
    <div class="photo_wrp">
        <img class="close" src="uploads/close.gif" />
        <div style="clear:both"></div>
        <div class="pleft">test1</div>

        <div class="pright">test2</div>

        <div style="clear:both"></div>
    </div>
</div>

now thing is class=pright contain comments print by php

my onclick function is only working on .pright enter image description here

 $(document).ready(function()
{
    $('.pright').click(function() {
         alert('this');
     });
});

my click function is not working on anything specially which is printed by php i want to click click is blue in picture

my code for that

<div class="pright">
    <div id=\"commentdiv\">
        <span id=\"commentspsn\"></span>
        <div id=\"comments_list\">  
        <div class=\"comment\"  id='12'>

             <p>Comment from 
               <span class=\"namecomment\">'ali'</span> 
               <span>( date )</span>:
             </p>
             <p><span id='first_1'>this</span></p>

             <textarea name=\"comment\"  class=\"editbox\"id='first_input_1'>this</textarea></div>
</div>
        </div>

STRUCK :s

M.chaudhry
  • 651
  • 1
  • 6
  • 13

1 Answers1

0

If you are loading Elements dynamically you need to make your code like this code works for me now prefectly working for me

 $(document).ready(function()
{
    $('.pright').on( 'click', 'div.commentclass', function(){
         alert($(this).attr('id'));
     });
});

as Barmar Thankfully provided corresponding link check this

Event binding on dynamically created elements?

there is link available for on() read this for sure :)

http://api.jquery.com/on/

Community
  • 1
  • 1
M.chaudhry
  • 651
  • 1
  • 6
  • 13