12-mayo-2012
admin

Propiedades nth-child y first-child de jquery.

JQuery tiene varias propiedades que se pueden utilizar para acceder a nodos concretos que están dentro de un nodo padre. Entre estas propiedades voy a comentar el funcionamiento de: first-child y nth-child

Para ello voy a utilizar un ejemplo. Supongamos que tenemos un Select cuyo id es «selectPrueba».

first-child – Se puede utilizar para seleccionar el primer elemento.
p.e. esto seleccionaria en el combo el primer elemento.

$('select#selectPrueba option:first-child').attr("selected", "selected");

nth-child – Permite seleccionar un elemento concreto.
p.e. esto seleccionaria en el combo el elemento 4.

$('select#selectPrueba option:nth-child(4)').attr('selected', 'selected');

Más información con ejemplos: first-child y nth-child.

6 Comentarios

  • I am genuinely glad to glance at this website posts which contains lots of valuable data, thanks for providing these kinds of information.

  • I recommend Utorrent for Windows and Azureus for all other platforms.
    The voyage of discovery isn’t in seeking new landscapes but also in having new eyes. By controlling yourself you happen to be switching off your neighbor.

  • Hey! I know this is kinda off topic but I was wondering if
    you knew where I could locate a captcha plugin for my
    comment form? I’m using the same blog platform as yours and I’m
    having problems finding one? Thanks a lot!

    Take a look at my blog post: deer hunter 2014 tutorial for game

  • All the high five music torrents can be found at Torrents – HQ.

    Physical activities and exercises that anyone can do as a way to
    stay away from hemorrhoid problems happen to be recommended.
    The band writes, records, mixes, and masters their songs
    in a basement studio in Glasgow.

  • Security is not just a mere statutory requirement but an important factor to compete globally.
    However, a few strands of wisdom and compassion, wove their
    way over the discussion from various posters that suggested another path.
    Traders searching for online possibilities to earn extra cash,but
    most with the time unable to find a reliable and convenient business online
    due for the fact that online income opportunities
    need large investments and charge commission on trade dealings
    turn to Forex Striker, which is becoming more and
    more popular due to the market liquidity.

Dejar un comentario

Categorias

Linkedin