Friday, June 24, 2016

Create Own function in jQuery


As per market demand and the use of jQuery its too difficult to understand the actuality of the function created by the developer because jQuery is so vast to under stand and work o it.
To get expert in jQuery developer need to know java-script in deep and small knowledge in jQuery .


Code with Explanation and complete understanding of code writing skill:


(function($){  /// defining the function with null function

$.fn.veeron=function(dharambir){    // proving the name of function by using $.fn.<<name of function>>

//custome setting
var data=$.extend({
name:'dharambir singh',//parameter definition with default value
color:'red',
fsize:'23px'
},dharambir);

return this.append('hello '+ data.name).css({color:data.color,'font-size':data.fsize});///returning the value with the default or user defined value which display in HTML page
}
}(jQuery));




Full Code for example:

<!DOCTYPE html>
<head>
<title>JQUERY TUT</title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function(){
$('#dac').veeron({
name:'Dharambir Singh',
color:'Blue',
fsize:'35px'
});
});
</script>
</head>
<body>
<div id='dac'>
</div>
</body>
<script>
(function($){

$.fn.veeron=function(dharambir){

//custome
var data=$.extend({
name:'dharambir singh',
color:'red',
fsize:'23px'
},dharambir);

return this.append('hello '+ data.name).css({color:data.color,'font-size':data.fsize});
}
}(jQuery));
</script>
</html>


No comments:

Post a Comment

Dharamart.blogspot.in