emehrkay Posted February 6, 2008 Share Posted February 6, 2008 doesnt work in firefox... Are you testing cross-browser? I would suggest get yourself a copy of firefox and the firebug plugin. The script crashed right on that line of code... Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 6, 2008 Author Share Posted February 6, 2008 intresting. I have both firefox and firebug. I didnt look at it though. I knew the status bar didnt work in ff so i just used it in safari since it did work, ill get rid of it, but i have a followup. Can i get all Attributes on a tag and store them into an array? i can use element.getAttribute('attribute'); but i cant get ALL of them Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 6, 2008 Share Posted February 6, 2008 Elements are objects and the attributes are properties of that object lets say you have this situation input.element = { type: 'text', value: 'some value', id: 'ele_id' }; So you access it like input.element.type or input.element['type']; YOu can loop through the attributes using a for in for(var x in input.element){ console.log(input.element[x]); } Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 6, 2008 Author Share Posted February 6, 2008 ok so say i have this <span id="1" style="color:blue" class="htext" name="number">My text</span> how would i get {id="1" , style="color:blue" , class="htext" , name="number"} or more appropriatley a 2d array [id][1] [style][color:blue] [class][htext] etc. Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 6, 2008 Share Posted February 6, 2008 Why do you want to make it an array? What are you trying to do? You may be adding more work Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 6, 2008 Author Share Posted February 6, 2008 actually, i dont need to do that anymore. I changed the ID when i needed to. UMMMMM you know how i was trying to getAttributes? Well some of the styles arent attributes like (<p style="color:blue">) some of the styles are up in the head <style type="text/css"> p {color:blue;} </style> how can i get those styles? Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 6, 2008 Share Posted February 6, 2008 element.style.whatever_attribute_you_need Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 7, 2008 Author Share Posted February 7, 2008 i got that part. let me be more specific. if (!document.getElementById || !document.createElement) return; // get the current element tag if (!e) var obj = window.event.srcElement; else var obj = e.target; // go up DOM till we get to a tag while (obj.nodeType != 1) { obj = obj.parentNode; } myObj = obj; //here i get the id attribute of the selected element cur_id = myObj.getAttribute('id'); //here i assign it to my textbox y.id = cur_id; so with that code i can inherit styles applied to it because it had an ID. BUT if the element doesnt have style because of an ID i cant do that. say this for example <html> <head> <style type="text/css"> p {color:blue} </style> </head> <body> <p> this text will be blue </p> how can i get the blue attribute into a variable so i can use it to apply it to the textbox like i did with the ID. I dont know how to access the <style type="text/css" in the heading Quote Link to comment Share on other sites More sharing options...
emehrkay Posted February 7, 2008 Share Posted February 7, 2008 You just have to know how to select elements. once you have them selected, all of the css properties are available to you. In your example var first_p = document.getElementsByTagName('p')[0]; first_p.sytle.color; //blue Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 7, 2008 Author Share Posted February 7, 2008 ok, what am i doing wrong here. This is when i click on a tag. if i do alert(myObj.id); it tells me the id thats on it, great. but if i do alert(myObj.style.color); its blank i also tried alert(myObj.style.fontFamily); still blank heres the css im trying to access (i know its messy) <style type="text/css" id="styles"> p {text-align:left;color:#333333;font-family:Times New Roman;font-size:17;} #head {text-align:left;color:#014342;font-family:Tahoma;font-size:20} #green {text-align:left;color:#014342;font-family:Times New Roman;font-size:17} </style> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 7, 2008 Share Posted February 7, 2008 In my experiences; your CSS style needs to be inline for JavaScript too recognize specific style attributes. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted February 7, 2008 Author Share Posted February 7, 2008 ahh nevermind i got it function getStyle(oElm, strCssRule){ var strValue = ""; if(document.defaultView && document.defaultView.getComputedStyle){ strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule); } else if(oElm.currentStyle){ strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); }); strValue = oElm.currentStyle[strCssRule]; } return strValue; } Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 7, 2008 Share Posted February 7, 2008 Good Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.