I'm in a bit of a problem here! And i wish for someone to help me!
This is what i think i have done.
I made my own getElementsByClass function, put it in a seperate js file.
Created one more whit a function for my specified class "external".
By nothing happens.
This is my function created for finding different classes (core.js), witch i revered to in my HTML file. (<script type="text/javascript" src="core.js">)
And here's my other function in the file javascript.js, <script type="text/javascript" src="javascript.js"> (placed after the core.js) witch i want to execute while clicking on the links of the class "external".
But nothings happens. I'm a to much of an beginner whit javascript. And my error massage the core is not defined don't make any sense to me.
I would be pleased if someone could help me solve my problem and make the function work! (witch i'd almost created from reading a book, that makes it even more strange.) /// Jen.
This is what i think i have done.
I made my own getElementsByClass function, put it in a seperate js file.
Created one more whit a function for my specified class "external".
By nothing happens.
This is my function created for finding different classes (core.js), witch i revered to in my HTML file. (<script type="text/javascript" src="core.js">)
Code:
Core.getElementsByClass = function(theClass) { var elementArray = []; if (typeof document.all!= "undefined") { elementArray = document.all; } else { elementArray = document.getElementsByTagName("*"); } var matchedArray =[]; var pattern = new RegExp("(^| )" + theClass + "( |$)"); for (var i =0; i < elementArray.length; i++) { if (pattern.test(elementArray[i].className)) { matchedArray[matchedArray.length] = elementArray[i]; } } return matchedArray; };
Code:
var TheLink = { init: function() { var link = Core.getElementsByClass("external"); for (var i = 0; i <link.length; i++) { link[i].onclick = TheLink.externalLink; } }, externalLink: function() { return confirm("Vill du verkligen?"); } }; Core.start(TheLink);
I would be pleased if someone could help me solve my problem and make the function work! (witch i'd almost created from reading a book, that makes it even more strange.) /// Jen.
Comment