473,789 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ie getAttribute problems

43 New Member
Hi, so i done script like that

Expand|Select|Wrap|Line Numbers
  1.     body : function() {
  2.         for (i = 0; i < all_divs.length; i++) {
  3.             if (all_divs[i].title) {
  4.                 addEvent(all_divs[i], "mouseover", this.onover);
  5.                 addEvent(all_divs[i], "mouseout", this.onout);
  6.  
  7.                 all_divs[i].setAttribute("tooltip", all_divs[i].title);
  8.                 all_divs[i].removeAttribute("title");
  9.             }
  10.         }
  11.     }, 
  12.  
  13.     onover : function() {
  14.         var msger = document.getElementById("msger");
  15.         msger.innerHTML = this.getAttribute("tooltip");
  16.     },
  17.  
So firefox prints out tooltip but the ie6 doesn't so what should i do that ie would print tooltip attribute
Mar 22 '08 #1
7 2228
gits
5,390 Recognized Expert Moderator Expert
hmmm, strange ... is it a problem with getAttribute() or another one? when you assign a fixed text is that displayed in the innerHTML of 'msger'?

kind regards
Mar 22 '08 #2
tader
43 New Member
the problem is with getAttribute(); ie can not get it if i do it like that all_divs[0].getAttribute(" tooltip"); it works but when im using this.getAttribu te("tooltip"); it doesn't work on ie on ff everything is ok. I need it to work on this.
Mar 23 '08 #3
gits
5,390 Recognized Expert Moderator Expert
could you trace that this.tagName is the div you want to retrieve? may be you could try an additional property for the div like:

Expand|Select|Wrap|Line Numbers
  1. all_divs[i].tooltiptext = 'your_text';
  2.  
and later on retrive it with:

Expand|Select|Wrap|Line Numbers
  1. this.tooltiptext;
kind regards
Mar 23 '08 #4
tader
43 New Member
hm... that didn't work dam it ;] mabey if i give you full script it will help you to see the problem

Expand|Select|Wrap|Line Numbers
  1. var all_divs = document.getElementsByTagName("a");
  2.  
  3. var onload_init = {
  4.     xCord : 0, 
  5.     yCord : 0,
  6.  
  7.     body : function() {
  8.         for (i = 0; i < all_divs.length; i++) {
  9.             if (all_divs[i].title) {
  10.                 addEvent(all_divs[i], "mousemove", this.onover);
  11.                 addEvent(all_divs[i], "mouseout", this.onout);
  12.  
  13.                 all_divs[i].setAttribute("tooltip", all_divs[i].title);
  14.                 all_divs[i].removeAttribute("title");
  15.             }
  16.         }
  17.     }, 
  18.  
  19.     getCords : function(evt) {
  20.         if (document.captureEvents) {
  21.             onload_init.xCord = evt.pageX;
  22.             onload_init.yCord = evt.pageY;
  23.         } else {
  24.             onload_init.xCord = window.event.clientX;
  25.             onload_init.yCord = window.event.clientY;
  26.         }
  27.     },
  28.  
  29.     createTooltip : function() {
  30.         var div_element = document.createElement("div");
  31.         div_element.setAttribute("id", "tooltip_box");
  32.         div_element.style.visibility = "hidden";
  33.         document.body.appendChild(div_element);
  34.     },
  35.  
  36.     onover : function(evt) {
  37.         var tooltip_div = document.getElementById("tooltip_box");
  38.         onload_init.getCords(evt);
  39.  
  40.         if (tooltip_div == null) onload_init.createTooltip();
  41.         tooltip_div.style.top = (onload_init.yCord + 12) + "px"
  42.         tooltip_div.style.left = (onload_init.xCord + 12) + "px"
  43.         tooltip_div.style.visibility = "visible";
  44.  
  45.         tooltip_div.innerHTML = "";
  46.  
  47.         // here is the problem this.getAttribute doesn't get text on ie
  48.         var inner_text = this.getAttribute("tooltip");
  49.         var ctn = document.createTextNode(inner_text);
  50.         tooltip_div.appendChild(ctn);
  51.     },
  52.  
  53.     onout : function() {
  54.         var tooltip_div = document.getElementById("tooltip_box");
  55.         tooltip_div.style.visibility = "hidden";
  56.     }
  57. };
  58.  
  59.  
  60. function load_page() { onload_init.body(); }
  61. addEvent(window, "load", load_page);
  62.  
  63. function addEvent(object, eventType, do_function){
  64.     if (object.addEventListener){
  65.         object.addEventListener(eventType, do_function, true);
  66.         return true;
  67.     } else if (object.attachEvent){
  68.         var to_return = object.attachEvent("on" + eventType, do_function);
  69.         return to_return;
  70.     } else {
  71.         return false;
  72.     }
  73. }
  74.  
Mar 23 '08 #5
gits
5,390 Recognized Expert Moderator Expert
hmmm ... first you should move the line where you retrieve your 'all_divs' into the onload-object so that the dom is ready to use for it?

could you try to alert innerHTML of the node instead of trying to retrieve the tooltip-attribute? does that work and is it the innerHTML of the correct node?

i just cannot test it since i'm using a mac an so no IE :) ... so i think we have to make little steps towards the solution ...

kind regards
Mar 23 '08 #6
tader
43 New Member
script is working file now i just updated addEvent function to this

Expand|Select|Wrap|Line Numbers
  1. function addEvent(obj, type, fn) {
  2.     if (obj.addEventListener) {
  3.         obj.addEventListener(type, fn, false);
  4.         return true;
  5.     } else if (obj.attachEvent) {
  6.         obj["e" + type + fn] = fn;
  7.         obj[type + fn] = function() { 
  8.             obj["e" + type + fn]( window.event ); 
  9.         }
  10.         var treturn = obj.attachEvent("on" + type, obj[type + fn]);
  11.         return treturn;
  12.     } else {
  13.         obj["on" + type] = obj["e" + type + fn];
  14.     }
  15. }
  16.  
so thx for your help anyway ;]
Mar 24 '08 #7
gits
5,390 Recognized Expert Moderator Expert
glad to hear you got it working ... :)

but i'm just wondering whether the line:

Expand|Select|Wrap|Line Numbers
  1. var all_divs = document.getElementsByTagName("a");
always works? is it called onload or before? typically it is a little bit unreliable to retrieve dom-nodes during page load ... so it is better to do it after the page is fully loaded and so the dom too?

kind regards
Mar 24 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4745
by: mr_burns | last post by:
Hi, I have the following code that works fine except the getAttribute line: var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("note.xml"); nodes = xmlDoc.documentElement.childNodes; text = '<p>note:<br>';
3
21925
by: hutch | last post by:
Hi, I'm making use of this VERY useful function for a so called 'standards compliant' replacement for target="_blank": function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=0; i<anchors.length; i++) { var anchor = anchors;
6
10026
by: Banski | last post by:
Hi, Im quite new to XML in .Net. Im getting values from an xml file using XPath and sorting as you see in the code below. I cant figure out how to get the value of date with GetAttribute. Hope that this short description if enough and you can help to sort out this problem. Thanks in advance banski
2
7632
by: DN | last post by:
This works: nav.GetAttribute("@ATTRIBUTE",""); This doesn't: string strTemp = "@ATTRIBUTE"; nav.GetAttribute(strTemp,""); Anybody know a way around this?
3
3478
by: duff | last post by:
Hiya, I'm trying to replace the commented out code below with a neater version using the IAttributeAccessor interface (so that I don't have to write 'if' statements for all control types). At the moment this doen't work. The test line I put in (string s = ControlAttributes.string s = ControlAttributes.GetAttribute ("Text");
13
3237
by: Noa | last post by:
Hi I have a page that looks like that: <form name="kuku1" action ="anotherpage.html" > <input name="name"> <input name="kuku2"> </form> As far as i know, "getAttribute" should return a string value of an
2
5851
by: christopher.secord | last post by:
I'm having a hard time understanding an error that I'm getting. In the code below, I'm trying to call substring() on an attribute of an anchor. The error I get says "getAttribute("rel") has no properties" The reason this confuses me is that getAttribute("rel") returns a string, so it should have all the properties and methods of a string, right?? What am I missing here? - chris
3
5899
by: jphaycock | last post by:
Hi all I am trying to get a url attribute from an xml node: <item> <media url="http://blablabla.com" /> </item> I can do this in IE with the following code: var newDom = xmlhttp.responseXML; var x = newDom.getElementsByTagName("item");
4
2882
by: RobG | last post by:
I have always accessed attributes such as disabled using the DOM element property, however I was wondering about implementing a more generic function to get the values of attributes - which of course leads to the DOM Element Interface's getAttribute method: <URL: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-666EE0F9 > The DOM 2 Core specification says that getAttribute should return the value of an attribute as a string, however...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.