$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
$(document).on("click", ".onClass", function () {
//your code
var element = $(this); // to get clicked element
});
$( "#other" ).click(function() {
$( "#target" ).click();
});
$( "p" ).on( "click", function() {
alert( $( this ).text() );
});
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
//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
$(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>
$("p").click(function(){
alert("The paragraph was clicked.");
});
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();
});