I have tag trigger working by setInterval and it alerts when it find the tag in the document. the code did not have any problem until I’ve got the function into an object for arrangement,
Live examples:
- here is an working example without object : http://jsfiddle.net/ae6Xc/4/
- here is example with object (with the problem) : http://jsfiddle.net/ae6Xc/10/
here is the “original” working code without the object:
// looking for the special tag than save the
// element in varabile and than alert
(function(){
var win = window ,
doc = document ,
setInter = 'setInterval' ,
clearInter = 'clearInterval' ,
getByTagName = 'getElementsByTagName' ,
KW_pluslike = 'mysite:plugin' ,
zero = 0 ,
element;
// Set 'setInterval' function as trigger
// to target the Special tag.
var trigger = win[setInter](function(){
// Check if such tag exist , if not repeat. When the tag
// has founded , it set the root to the Element var.
if(doc[getByTagName](KW_pluslike)[zero]){
element = doc[getByTagName](KW_pluslike)[zero];
win[clearInter](trigger);
alert("Tag Captured");
}
} , 1000 /5 );
})();
so as i said , i wanted to arrange the things up a little so i took the Trigger function and the Element variable and replaced them into an object like this :
var pluslike = {
element : nul ,
trigger : win[setInter](function(){
if(doc[getByTagName](KW_pluslike)[zero]){
pluslike.element = doc[getByTagName](KW_pluslike)[zero];
win[clearInter](pluslike.trigger);
alert("Tag Captured");
}
} , 1000 /5 );
}
pluslike.trigger;
somehow for some reason it’s not working , what causes the problem? i don’t know. when it started? when i used the function in object.
thank you in advance.
A semicolon inside the object literal is causing your problem. Fixed code: http://jsfiddle.net/ae6Xc/11/
Inside an object literal, properties should be separated by commas. Semicolons are not allowed
Comparison of your code, and the patched code: