xxxxxxxxxx
$(document).on("click", ".onClass", function () {
//your code
var element = $(this); // to get clicked element
});
xxxxxxxxxx
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
xxxxxxxxxx
//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
xxxxxxxxxx
<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>
xxxxxxxxxx
1
2
3
$( "#dataTable tbody" ).on( "click", "tr", function() {
console.log( $( this ).text() );
});
xxxxxxxxxx
$(document).on('click touch', '.your-element', function () { });
xxxxxxxxxx
var myEl = document.getElementById('myelement');
myEl.addEventListener('click', function() {
alert('Hello world');
}, false);
myEl.addEventListener('click', function() {
alert('Hello world again!!!');
}, false);