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

Discussion in 'JavaScript' started by cj333, Feb 5, 2011.

  1. #1
    I have many articles. Article structure as follows
    <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-->
    HTML:
    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...

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