1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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