Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    a testing question!

    no rush at all on this _
    i'm doing an online jQuery course and in one exercise they have posted a question erroneously _ it's not included in the answers BUT i just wondered if anyone here would like to puzzle it out

    create a jQuery selector for_
    the last element in any section of the page which is a <p> tag
    (the exercise page had a <header> <article> and <footer> sections)

    i had a go but i am a newbie to this and couldn't get it _
    thought i'd throw it open to the experts on CF

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,470
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Presumably jQuery allows you to use the pseudo selector so the answer would be whichever of the following three corresponded to the section of the page you wanted to find the last paragraph in:

    header>p:last-of-type
    article>p:last-of-type
    footer>p:last-of-type

    at least that's how you can reference them from CSS and to the best of my knowledge that's how jQuery selectors work even in older browsers that don't support them directly in the CSS.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    ifcDeveloper (03-18-2013)

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,479
    Thanks
    6
    Thanked 981 Times in 954 Posts
    I believe the last-of-type selector wasn’t included in the sizzle selector engine jQuery is using. However, the non-standard :last selector is and I would interpret the question to simply mean this:
    Code:
    $('p:last')
    Which would address any paragraph that is a last child of any section in the document.

  • Users who have thanked VIPStephan for this post:

    ifcDeveloper (03-18-2013)

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    hey guys _ thanks for such a fast response!

    sadly neither answer works!
    i recognise the .last method and ran the code you wrote on the exercise question_ i appended your code with .css(background-color" etc) but only the last paragraph is highlighted

    as far as i can tell the trick would be in how to bring the 3 sections together before applying the 'last paragraph' clause_ perhaps as the 'method' element
    $("something in here").find("p.last");

    anyway guys _ my thanks again
    Last edited by ifcDeveloper; 03-18-2013 at 11:45 PM.


  •  

    Posting Permissions

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