Richard
Richard

Reputation: 32979

Click event not firing in jQuery Mobile?

See this fiddle: http://jsfiddle.net/Bg9Zx/5/

Relevant code:

<fieldset data-role="controlgroup" data-type="horizontal" id="locate-me">
<input type="checkbox" name="loc" id="loc" />
<label for="loc">Locate me</label>
</fieldset>
$("#loc").click(function(){
   alert('locate clicked!');
});

Why isn't the .click() event firing? Works perfectly fine if I don't reference jQuery Mobile.

Thanks!

Upvotes: 0

Views: 6612

Answers (2)

Dynamikus
Dynamikus

Reputation: 2968

You are referecing it wrong. #loc refers to an ID of an element use this instead.

<label class="test" for="loc">Locate me</label>

$(".test").click(function(){
   alert('locate clicked!');
});

Upvotes: 6

Dave Long
Dave Long

Reputation: 794

Probably because your jQuery code is not wrapped in script tags. Try the following :

<fieldset data-role="controlgroup" data-type="horizontal" id="locate-me">
<input type="checkbox" name="loc" id="loc" />
<label for="loc">Locate me</label>
</fieldset>
<script type="text/javascript">
$("#loc").click(function(){
   alert('locate clicked!');
});
</script>

Hope that helps. Dave

Upvotes: 0

Related Questions