Jump to content

changing text


optikalefx

Recommended Posts

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

Link to comment
Share on other sites

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]);

}

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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;
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.