#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    206
    Rep Power
    11

    Adding a CSS class using JQuery


    Hi,

    Is it possible to adding a CSS class to the 1st occurance of an element on a page? I have a list of lines like this:
    <div class="theline"><a href=page.html"></a></div>
    <div class="theline"><a href=page.html"></a></div>
    <div class="theline"><a href=page.html"></a></div>
    <div class="theline"><a href=page.html"></a></div>

    Is is possible to add a CSS class (class="myclass") to just the first occurance of the above lines of code using Jquery?

    Thanks in advance
  2. #2
  3. garish grotesque gargoyle
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Mar 2006
    Location
    gracing gargantuan gothic gateways
    Posts
    1,337
    Rep Power
    1038
    try reading up on how jQuery works... this kind of thing is exactly what jQuery is for, and is covered in almost every doc and tutorial.

    Code:
    $('.theline:eq(0)').addClass('myclass');
    How To Get Anything You Want - Learning jQuery

    good luck

IMN logo majestic logo threadwatch logo seochat tools logo