11684
11684

Reputation: 7517

jQuery not working on clicking radiobutton

my code:

$(document).ready(function(){
    alert("document ready");

    $("input[type=radio]").click(function(event){
        alert("clicked");
    });
});

But no alert shows up... And, when typing in on the console:
$(document).ready(function(){ alert("document ready");}) I get the alert! What is going on here?

Upvotes: 4

Views: 11206

Answers (4)

11684
11684

Reputation: 7517

I found the solution, it explains as well why it does work in JSFiddle.
The problem was how I imported jQuery: I did

<script type="text/javascript" src="jQuerylink" />

and it had to be

<script type="text/javascript" src="jQuerylink" ></script>

I don't know why this is so, but now it works. Thanks for all effort.

Upvotes: 2

Shyju
Shyju

Reputation: 218862

$(function(){

    $("input[type='radio']").click(function(){
      alert("clicked");
    });        

});​

Example http://jsfiddle.net/Dw6Fp/2/

Upvotes: 1

Jovan Perovic
Jovan Perovic

Reputation: 20201

According to the jQuery selector docs [link] you should enclose parameter value with double quotes:

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

OR

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

UPDATE: JSFiddle example

Upvotes: 0

mguymon
mguymon

Reputation: 9015

try .change() instead of .click()

$(document).ready(function(){
    alert("document ready");
    $("input[type=radio]").change(function(){
        alert("clicked");
    });
});

Upvotes: 4

Related Questions