In a jQuery function I am getting event on form's element click event. Now I want to get its html. How it is possible ?
For Example:
function(event, ID, fileObj, response, data) {
alert( $(event.target) ); // output: [object Object]
alert( event.target ); // output: [object HTMLInputElement]
alert( $(event.target).html() ); // output: (nothing)
}
I want to get form object who's element is clicked through event
Thanks
You can try event.target.outerHTML
, however I'm not sure how well supported it is across all browsers. A more convoluted but sure to work solution would be to wrap the element in another element, then take the html of the parent element:
$('<div/>').html($(event.target).clone()).html();
If your event is a click
you can bind it using the click()
method from jQuery. Use this
to reach your element, like the code below:
$('#id').click(function(event){
console.log($(this));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With