Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-11-2011, 06:10 AM   PM User | #1
runeveryday
Regular Coder

 
Join Date: Jul 2009
Posts: 152
Thanks: 8
Thanked 0 Times in 0 Posts
runeveryday can only hope to improve
live() instead in jquery 1.26?

Code:
$('#content').find('p:eq(0)').append('<span class="more"> | more</span><span class="less"> | less</span>')
$('p:gt(0)').hide();

$('.more, .less').live('click', function() {
    $('#content').find('p:gt(0)').slideToggle();
    $('.more, .less').toggle();
})
i using drupal-6,the jquery is 1.26. if i don't want to upgrade the jquery. is there a way to get the effect?

jquery is 1.26 haven't have a suppport to the live() function. is there another function can instead of it. or alter the code to get the effect?


some one told me to dd a normal click handler to .content, then check whether $(e.target).is('.more, .less').


i alter the code to this
Code:
 $('#content').find('p:eq(0)').append('<span class="more"> | more</span><span class="less"> | less</span>')
 $('p:gt(0)').hide(); 
$('#content').click(function(){
 if($(e.target).is('.more, .less'))
{
 $('#content').find('p:gt(0)').slideToggle(); $('.more, .less').toggle(); 
} 
})
but it can't work.
runeveryday is offline   Reply With Quote
Old 04-11-2011, 08:30 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
The code is missing the "e" parameter ... it should work then
Code:
$('#content').click(function(e){
   if($(e.target).is('.more, .less')) {
      $('#content').find('p:gt(0)').slideToggle();
      $('.more, .less').toggle(); 
   } 
});
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
runeveryday (04-12-2011)
Old 04-12-2011, 02:03 AM   PM User | #3
runeveryday
Regular Coder

 
Join Date: Jul 2009
Posts: 152
Thanks: 8
Thanked 0 Times in 0 Posts
runeveryday can only hope to improve
Quote:
Originally Posted by devnull69 View Post
The code is missing the "e" parameter ... it should work then
Code:
$('#content').click(function(e){
   if($(e.target).is('.more, .less')) {
      $('#content').find('p:gt(0)').slideToggle();
      $('.more, .less').toggle(); 
   } 
});
you're my hero! could you explain what's the function meaning?
runeveryday is offline   Reply With Quote
Old 04-12-2011, 07:01 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Instead of binding a click handler to the (yet non existing) classes more/less you bind a click handler to the container #content. Each element inside this container propagates ("bubbles") its click events up in the DOM tree to the next higher level elements (including #content). The click handler there can check which element originally received the click event using e.target

.is() can tell you which class(es) the clicked element belongs to ... and the rest is your original code.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.