Jump to content

Archived

This topic is now archived and is closed to further replies.

optikalefx

changing text

Recommended Posts

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...

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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]);

}

Share this post


Link to post
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.

 

 

Share this post


Link to post
Share on other sites

Why do you want to make it an array? What are you trying to do? You may be adding more work

Share this post


Link to post
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?

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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>

 

Share this post


Link to post
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;
}

 

Share this post


Link to post
Share on other sites

×
×
  • 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.