Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  55] [ 6]  / answers: 1 / hits: 21971  / 12 Years ago, fri, june 15, 2012, 12:00:00

well I want to debug some script with Firebug, (cause I can't see anything in the browser window) but when I click the script tab in Firefox it gives me the error message:



If tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct).



What am I doing wrong?



Here's my code:



<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>



<script src=jquery-1.7.1.js></script>
<script type=text/javascript>
$(function() {
/* fix: “close” the value of i inside createFunction, so it won't change */
var createFunction = function(i) {
return function() { alert(i); };
};

for (var i=0; i<5; i++) {
$('p').appendTo('body').on(click, createFunction(i));
}

})();
</script>
</body>
</html>

More From » jquery

 Answers
36

You must leave out the last parenthesis, I guess the code should run on dom ready?



<script type=text/javascript>
$(function() {
/* fix: “close” the value of i inside createFunction, so it won't change */
var createFunction = function(i) {
return function() { alert(i); };
};

for (var i=0; i<5; i++) {
$('<p>').appendTo('body').on(click, createFunction(i));
}

});
</script>


See here for how to make code running on dom load with jquery.


[#84877] Thursday, June 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karivictoriab

Total Points: 530
Total Questions: 90
Total Answers: 95

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;