How to trigger function in DIV
The events in the object fires when the page loads, mouse events , keyboard events and other types of inputs. It is not possible to trigger an event in the DIV for example, onload event when the object is loaded. Some elements like body, script, link, image, style support firing up of events. However, it is required for the developer to trigger the event in object DIV. In order to do that we can use jquery trigger method to fire the event.
HTML
<div onload="$(this).text('I will display in Div using text()');"></div>
<div onload="welcome()"></div>
Javascript/Jquery
function welcome(){
alert('Hello world! in func welcome');
}
$(function(){
$('div[onload]').trigger('onload');
});
No comments:
Post a Comment