Sunday, May 1, 2011

jQuery Form Input

I'm trying to use a radio button as a click function:

$("input[type=radio]").click(function(){

and I don't just want radio buttons, I want radio buttons with the class 'baby', or I could even do it by name if that's easier, searched google and I can't find anything :(

From stackoverflow
  • How about this :

    $("input[type=radio][class=baby]").click(function(){
    
    moff : Or perhaps even simpler: input[type=radio].baby
    David Dorward : .baby is preferable. [class=baby] won't match class="baby somethingElse"
  • You can have multplie selectors

    $("input[type=radio]", ".baby").click(function(){}
    

    Here you have nice examples

  • Use the first selector to globally pick up your inputs and then filter using a second selector.

    $("input[type=radio]").filter(".baby")
    

0 comments:

Post a Comment