Grow your CSS skills. Land your dream job.

Form Element Targeting

  • # June 14, 2009 at 1:45 pm

    Hi,

    I’m new to jquery and wanted to know more information about targeting (selectors and such) form elements such as input, checkbox, select (and option) based on their values, classes or other values and based on that do something (probably an if statement).

    Anything you could tell me would be great.

    Rob
    # June 14, 2009 at 2:42 pm

    Hey :)

    there are LOADS of options in this subject, jQuery gives you lots of ways. BUT to get you going, and all you will need for now, here is some advice!

    Think CSS. jQuery will select like you would select in to style in CSS.

    Example:

    <div id="TheBox" />
    <div class="TheBox" />
    <p>

    Ok I have a div with the ID of "TheBox", and a class of "TheBox" and a plain P – in css I would select like this…

    #TheBox { /* CSS Stuff */ }
    .TheBox { /* CSS Stuff */ }
    p { /* CSS Stuff */ }

    In jQuery you do this…

    $("#TheBox")
    $(".TheBox")
    $("p")

    you can even drill down to select things, or multipul items like in CSS…

    $("#one, #two, #three")

    <div id="one" />
    <div id="two" />
    <div id="three" />

    $("#one #two)

    <div id="one">
    <div id="two" />
    </div>

    Hope that helps :)

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".