2 Replies - 684 Views - Last Post: 22 June 2010 - 08:24 AM

#1 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Javascript setting element position not working

Posted 22 June 2010 - 07:14 AM

Hi all,

I am making a small text editor for text areas on my website.
Just to handle simple text formatting etc...

I have an emoticon button which I want to display a <div> of all the emoticons below the actual emoticon button.

I have the javascript code to find the left and top positions of the emoticon button, which spits out numbers that look correct.

However in my show_emoticons function the left and top style setting is never getting set, in firebug they are just displayed as ""

function show_emoticons(id)
{
	var el = document.getElementById(id + '_emoticons_list');
		
	if(el.style.display == "none")
	{
		el.style.display = "block";
		var parent = document.getElementById(id + '_emoticons');
		el.style.left = findPosX(parent);
		el.style.top = findPosY(parent) + parent.style.height;
	}
	else
	{
		el.style.display = "none";
	}
}



I'm probably doing something stupid but I just cannot figure this out.

findPosX and findPosY both give out valid numbers when using firebug to find the problem.

Any help on this would be much appreciated.
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Javascript setting element position not working

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 2894
  • View blog
  • Posts: 7,548
  • Joined: 08-June 10

Re: Javascript setting element position not working

Posted 22 June 2010 - 08:09 AM

do findPosX()/findPosy() return the bare numbers or inluding units? if the units are omitted, the browser most likely ignores the values (i.e. what is 10? 10em, 10ex, 10px, 10pt, 10%, 10cm, 10mm, …)

This post has been edited by Dormilich: 22 June 2010 - 08:10 AM

Was This Post Helpful? 2
  • +
  • -

#3 p0is0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 47
  • Joined: 19-February 10

Re: Javascript setting element position not working

Posted 22 June 2010 - 08:24 AM

View PostDormilich, on 22 June 2010 - 07:09 AM, said:

do findPosX()/findPosy() return the bare numbers or inluding units? if the units are omitted, the browser most likely ignores the values (i.e. what is 10? 10em, 10ex, 10px, 10pt, 10%, 10cm, 10mm, …)


That was it, thanks.
I had missed the px off the end.

Thanks a lot!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1