$( "#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() );
});
//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","#test-element",function() {});
$(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.");
});
$(document).on('click touch', '.your-element', function () { ... });
1
2
3
$( "#dataTable tbody" ).on( "click", "tr", function() {
console.log( $( this ).text() );
});
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();
});