script
tag. $.fn
object. So that, one can access all methods from $.fn
object and can add own method to $.fn
object. jQuery.getId.js
[javascript]
$.fn.getID = function()
{
return this.each(function()
{
alert('ID of Clicked Element:"' + $(this).attr("id") + '".');
}
}
[/javascript]
The jQuery.getId.js
is the new plugin file. In this file, create new method getID()
to know the ids of clicked elements with the help of existing method attr()
.
Link the own plugin file into the website with the help of script
tag. Check this below example for more help.
[html]
<!DOCTYPE html>
<head>
<title>jQuery Plugins</title>
<script src="jquery.js"></script>
<script src="jquery.getid.js"></script>
</head>
<body>
<p>This is a paragraph</p>
<div>This is a div</div>
<button id="btnClick">Click</button>
</body>
</html>
[/html]