SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Whether jQeury can according to article words, automatically add a toggle function?

    I have many articles. Article structure as follows
    HTML Code:
    <div class="selected">
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    ...<!--many p-->
    </div>
    <div class="selected">
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    <p>[I]some word[/I]</p>
    ...<!--many p-->
    </div>
    ...<!--many div.selected-->
    Whether jQeury can according to article words, automatically add a toggle function?
    I need show the first 3 <p></p> and toggle the rests <p></p>.

    I am newer for jQuery, I read some article from jquery.com, and write this one, but lack of something...

    HTML Code:
    jQuery('.selected').find('p:nth(3)').add('<a class="toggle">view more</p>');
    $('.toggle').click(function () {
     $("p").toggle();
    });

  2. #2
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pump up


Tags for this Thread

Bookmarks

Posting Permissions

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