fakeguybrushthreepwood
fakeguybrushthreepwood

Reputation: 3073

Using jQuery mobile button to run javascript

Using a script that reference jQuery Mobile I have the following line:

<a href="#" id="buttonAnswer1" data-role="button" data-inline="true" >check</a>

How would I add a listener for when this button is clicked and lets say call the hello() function? i.e.

<a href="#" id="buttonAnswer1" data-role="button" data-inline="true">check</a>

<script>
function hello(){
  console.log("hello world");
}
</script>

Upvotes: 0

Views: 153

Answers (1)

Jack
Jack

Reputation: 10993

This isn't really any different then regular jQuery, that is you can use .on to bind an event handler

For example, using .on with event delegation

$(document).on('click', '#buttonAnwser1', hello);

Or you can bind it directly

$('#buttonAnswer1').on('click', hello);

Upvotes: 1

Related Questions