"custom jquery plugin (for understanding extends)(check it in your local)"
Bootstrap 4.1.1 Snippet by mdburhani52

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="list1"></div>
<!--call jquery.js in script tag-->
<!--call plugin file in script tag-->
<script>
$('.list1').customPlugin1({
bgColor: '#a7a7a7',
data: [
{name: "mohammad", age: 24, gender: 'male', className: "myClass"},
{name: "atif",age: 24,gender: 'male'},
{name: "girish",age: 24,gender: 'male'},
]
})
</script>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function ($) {
$.fn.extend({
customPlugin1:function(params){
myFn1(this.selector, params);
return
},
});
var myFn1 = function(selectorName, params){
var output = '';
for (var i = 0; i < params.data.length; i++) {
var customClass = "";
if(params.data[i].hasOwnProperty('className')){
customClass = params.data[i].className;
}
output += '<div class="' + customClass + '">' + params.data[i].name + '</div>';
}
$(selectorName).html(output);
$(selectorName).css({background:params.bgColor})
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: