$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
$('#selector').on('click',function(){
//Your code here
});
$( "p" ).on( "click", function() {
alert( $( this ).text() );
});
$("#button").click(function () {
//result show on console.
console.log("Button Was Click");
//console.log(this);
});
//1st way
$(".searchCategory").click(function () {
//your code here
});
//2nd way
$(".searchCategory").on( "click",getCategory); // getCategory is a function but don't need the pharenthesis
//if you write getCategory() instead of getCategory when getCategory is a function with no pharamenters it might not work
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
$(document).on('click' , '.class' , function(){
//event
})
<script>
$(document).ready(function(){
$("#btn-txt").click(function(){
var ptext = $("#my-para").text();
alert(ptext);
});
});
</script>
<button type="button" id="btn-txt">Get Text Content</button>
<p id="my-para">This is a paragraph to Show jQuery text method.</p>
function example() {
}
function exampleParams(string, number, bool) {
}
//to call a function onclick without passing arguments
$(selector).click(example);
//to call a function onclick and pass arguments
$(selector).click(function() {
exampleParams("string example", 3, true);
});
$(document).on('click touch', '.your-element', function () { ... });
1
2
3
$( "#dataTable tbody" ).on( "click", "tr", function() {
console.log( $( this ).text() );
});
<script>
$(document).ready(function() {
$("p").click();
});
</script>
var myEl = document.getElementById('myelement');
myEl.addEventListener('click', function() {
alert('Hello world');
}, false);
myEl.addEventListener('click', function() {
alert('Hello world again!!!');
}, false);
$( "#other" ).click(function() {
$( "#target" ).click();
});