![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
window.onload = function() { if (!document.getElementsByTagName) return false; var lnks = document.getElementsByTagName("a"); for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { alert("is pop up type class"); lnks[i].onclick = function x() { popUp(this.getAttribute("href")); return false; |
#3
| |||||
| |||||
|
|
This is an example in "DOM Scripting". It works. I don't understand why. |
|
window.onload = function() { if (!document.getElementsByTagName) return false; var lnks = document.getElementsByTagName("a"); for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { |
|
alert("is pop up type class"); lnks[i].onclick = function x() { popUp(this.getAttribute("href")); return false; |
|
} } } } |
|
And here is the anchor a href="http://www.dogpile.com" class="popup" >POPUP</a><br/ To create his "unobtrusive" javascript, there is a test for existence of getElementByTagName. He returns false if it does not exist. I thought false precluded the default behavior or the <a> element. Shouldn't the test return true if the object is not found so that the page can load dogpile? |
#4
| |||
| |||
|
|
On Dec 15, 4:41 pm, mk83... (AT) yahoo (DOT) com wrote: window.onload = function() { if (!document.getElementsByTagName) return false; var lnks = document.getElementsByTagName("a"); for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { Oops. MS botched getAttribute. Won't work for "class." Use the className property instead. |
|
alert("is pop up type class"); lnks[i].onclick = function x() { popUp(this.getAttribute("href")); return false; This is a mistake too. The window might not open. Why, is getAttribute("href") wrong? |
|
Forgot to set lnks to null as well. This will leak memory in IE. |
#5
| |||
| |||
|
|
On Dec 15, 7:12 pm, David Mark <dmark.cins... (AT) gmail (DOT) com> wrote: On Dec 15, 4:41 pm, mk83... (AT) yahoo (DOT) com wrote: window.onload = function() { if (!document.getElementsByTagName) return false; var lnks = document.getElementsByTagName("a"); for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { Oops. MS botched getAttribute. Won't work for "class." Use the className property instead. What?, getAttribute("class") changes between browsers. |
|
That's a basic commonly used function. Do you encapsulate all calls to getAttribute then, or do you do tests on both tags, "class" and "className". Good grief! |
|
alert("is pop up type class"); lnks[i].onclick = function x() { popUp(this.getAttribute("href")); return false; This is a mistake too. The window might not open. Why, is getAttribute("href") wrong? |
#6
| |||
| |||
|
|
This is an example in "DOM Scripting". It works. I don't understand why. ... |
#7
| |||
| |||
|
|
mk83... (AT) yahoo (DOT) com wrote: Five hours and eleven minutes previously (according to my view of the world) you declared yourself a beginner. In the intervening time you've learned enough javascript to utterly confuse me, and I've been struggling with it for over ten years. I'd like to know what you're learning from. :-) -- Steve Swifthttp://www.swiftys.org.uk/swifty.htmlhttp://www.ringers.org.uk |
#8
| |||
| |||
|
|
On Dec 16, 12:58 am, Steve Swift <Steve.J.Sw... (AT) gmail (DOT) com> wrote: mk83... (AT) yahoo (DOT) com wrote: Five hours and eleven minutes previously (according to my view of the world) you declared yourself a beginner. In the intervening time you've learned enough javascript to utterly confuse me, and I've been struggling with it for over ten years. I'd like to know what you're learning from. :-) Just two main places (and now here) Started here "http:// www.w3schools.com/default.asp" and purchased a book titled "DOM Scripting" by Jeremy Keith. Good book. |
#9
| |||
| |||
|
|
On Dec 15, 7:12 pm, David Mark <dmark.cins... (AT) gmail (DOT) com> wrote: On Dec 15, 4:41 pm, mk83... (AT) yahoo (DOT) com wrote: for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { Oops. MS botched getAttribute. Won't work for "class." Use the className property instead. What?, getAttribute("class") changes between browsers. That's a basic commonly used function. |
#10
| |||||||
| |||||||
|
|
On Dec 15, 7:12 pm, David Mark <dmark.cins... (AT) gmail (DOT) com> wrote: On Dec 15, 4:41 pm, mk83... (AT) yahoo (DOT) com wrote: window.onload = function() { if (!document.getElementsByTagName) return false; var lnks = document.getElementsByTagName("a"); for (var i=0; i<lnks.length; i++) { if (lnks[i].getAttribute("class") == "popup") { Oops. MS botched getAttribute. Won't work for "class." Use the className property instead. What?, getAttribute("class") changes between browsers. That's a basic commonly used function. Do you encapsulate all calls to getAttribute then, or do you do tests on both tags, "class" and "className". Good grief! |
|
alert("is pop up type class"); lnks[i].onclick = function x() { popUp(this.getAttribute("href")); return false; This is a mistake too. The window might not open. Why, is getAttribute("href") wrong? |
|
Forgot to set lnks to null as well. This will leak memory in IE. I have to take care of destroying objects? I thought 'var this_or_that' was a local var. No? |
|
How would you know if there was a memory leak? Does is persist only |
|
during the browser session, or does it just lay there after all browser sessions are closed. |
|
This is going to be harder than I thought. I suppose a developer should have a copy of the popular browsers and test each page. |
|
Thank you very much. |
![]() |
| Thread Tools | |
| Display Modes | |
| |