I’m new to using jQuery. I tried to build a plugin, but it didn’t work. Why?
Here is what I have:
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
(function($){
$.alert = function(settings){
var config = {
// settings
'text': "old text",
'smily': ":(",
// ...
};
if ( settings ){$.extend(config, settings);}
// variables
var i = 0;
// script
alert(config.text + " " + config.smily);
};
</script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
$.alert(text: "new text", smily: ";)");
});
</script>
</body>
Assign the
$.extendreturn value (similar question)And call it like this:
Also remove the coma from the last default value
'smily': ":(",Click here for a working demo.