0

I have implemented showmore plugin by inserting this line of code:

<script src="script/showmore.js" type="text/javascript"></script>

and adding the 'more' class to:

 <span class='each_comment comment more'>

The plugin showmore works easily - you just need to add showmore class to a desired element and thats it. So it has nothing to do with click events! Now when user posts a new comment it appears on AJAX success call:

 $('.submit').after('<div class="combine_comment"><div class="user_area_comment"><img class="small_image_user" src="'+url_img+'"/><a href="home.php?u='+username+'"class="username_span">'+username+'</a></div><span class="each_comment comment more">'+comment+'</span> <time class="timeago" datetime="'+data+'">'+data+'</time></div></div>');    

As you can see I add 'more' class as well to the span of just added comment. But showmore plugin doesnot work with just added comment. I need to reload the page to see it working though the class is set properly. Do you know what might be wrong and why showmore plugin doesnt 'see' the more class of appended element? Maybe, it has something to do with load DOM? Thanks in advance for your attention and help.

Donatta
  • 25
  • 6
  • See [Event binding on dynamically created elements?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) you dont tell us anything about `showmore.js` but it must be adding the event handlers using `.click()` or similar which doesnt handle dynamic elements. Youll need to update it to use `.on()` like the linked question shows – Wesley Smith Oct 08 '16 at 07:10
  • Alternatively, the plugin may have a method to initialize the new elements after you create them, but again, you dont tell us anything about `showmore.js` so we cant say for sure – Wesley Smith Oct 08 '16 at 07:18
  • but the plugin works not like that! i just simply need to add class showmore to any element and thats all! It has nothing to do with .click event !!!! – Donatta Oct 09 '16 at 03:27
  • That's impossible for me to confirm or explain as you dont tell us what you are using. Can you provide a link to the plugin or create a jsFiddle so we can see the issue? I would bet a whole bunch of fake internet points that the issue has to do with dynamic event assignment ;) – Wesley Smith Oct 09 '16 at 09:19

0 Answers0