473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Setting styles with JS

Hello,
I am trying to change the style(Position of an image) with a
function.This code worked a month ago and I dont know what I changed
I'm only showing the relevant code. One image is superimposed on
another.
>From The html file:
--------------------------------------------------------------------
<script type="text/javascript">
function changenote(element) {

alert ("This Function is being Called");//Checking to see if the
function gets called, it does
var p = document.getElementById(element);
p.style.top =30;
p.style.left=30;

}

</script>

.......
<div id="GridBlock"><img alt="Blank Grid" src="crdgrid4.gif"
class="GridLayout" id="grid1" />
<img id="E"src="Root.gif" alt="none" class="Circle"
style="visibility:visible"></img>
<img id="A"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="D"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="G"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="B"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="e"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
</div>

..........

<td id="NoteA" width="22" class="Cellstyle"
onclick="changenote('E')"><a href="">A</a></td>

----------------------------------------------------------------------------
>From the Css:
..Circle {
position: absolute;

top: 63px;
left: 20px;
}

I am trying to change the position of "Root.gif" when I click the link
in the cell with id+"NoteA".
But nothing is changing.
Thanks
Mike

May 15 '07 #1
4 1633
On May 15, 2:28 am, Mike <ampel...@gmail.comwrote:
Hello,
I am trying to change the style(Position of an image) with a
function.This code worked a month ago and I dont know what I changed
I'm only showing the relevant code. One image is superimposed on
another.>From The html file:

--------------------------------------------------------------------
<script type="text/javascript">
function changenote(element) {

alert ("This Function is being Called");//Checking to see if the
function gets called, it does

var p = document.getElementById(element);
p.style.top =30;
p.style.left=30;

}

</script>

......
<div id="GridBlock"><img alt="Blank Grid" src="crdgrid4.gif"
class="GridLayout" id="grid1" />
<img id="E"src="Root.gif" alt="none" class="Circle"
style="visibility:visible"></img>
<img id="A"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="D"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="G"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="B"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
<img id="e"src="Root.gif" alt="none" class="Circle"
style="visibility:hidden"></img>
</div>

.........

<td id="NoteA" width="22" class="Cellstyle"
onclick="changenote('E')"><a href="">A</a></td>

---------------------------------------------------------------------------->From the Css:

.Circle {
position: absolute;

top: 63px;
left: 20px;

}

I am trying to change the position of "Root.gif" when I click the link
in the cell with id+"NoteA".
But nothing is changing.
Thanks
Mike
that is the worst piece of code i've seen in a long while.
add a return false statement, so from

<td id="NoteA" width="22" class="Cellstyle"
onclick="changenote('E')"><a href="">A</a></td>

to

<td id="NoteA" width="22" class="Cellstyle"
><a onclick="changenote('E');return false;" href="">A</a></td>
but seriously, that's all i'm going to say!

May 15 '07 #2
Mike wrote :
Hello,
I am trying to change the style(Position of an image) with a
function.This code worked a month ago
Worked? In which browsers? In which browser versions?

and I dont know what I changed
I'm only showing the relevant code.
That's not how serious debugging can be done, you see.
Not being able to see the whole code may prevent people from actually
figuring out your problem. Just posting an url would have been better, a
lot better.
One image is superimposed on
another.
>>From The html file:
--------------------------------------------------------------------
<script type="text/javascript">
function changenote(element) {

alert ("This Function is being Called");//Checking to see if the
function gets called, it does
var p = document.getElementById(element);
p.style.top =30;
[snipped]

W3C DOM2 Reflection of an Element's CSS Positioning Properties

CSS 1 and CSS 2.x specifications require that non-zero values must be
specified with a length unit; otherwise, the css declaration will be
ignored. Mozilla-based browsers, MSIE 6+, Opera 7+ and other W3C
standards-compliant browsers enforce such handling of parsing error.
CSS 1 Forward-compatible parsing
http://www.w3.org/TR/REC-CSS1#forwar...atible-parsing
CSS 2.1 Rules for handling parsing errors
http://www.w3.org/TR/CSS21/syndata.html#parsing-errors

See section 3.3.1.2 of
Using Web Standards in your Web Pages
http://developer.mozilla.org/en/docs...your_Web_Pages

So, here the correct js code must be
p.style.top = "30px";
Mike, post an url. First make sure your markup code passes HTML
validation and make sure your CSS code is valid.

Gérard
--
Using Web Standards in your Web Pages (Updated Apr. 2007)
http://developer.mozilla.org/en/docs...your_Web_Pages
May 15 '07 #3
>
So, here the correct js code must be
p.style.top = "30px";
Another option would be to work with a class rather than individual
style elements.

p.className = 'newclass';
May 15 '07 #4
I want the "R" image superimposed on the Fretboard.And Relative to the
upper left corner on the fretboard

I want it to reposition when I click the "A" Link
http://www.ampsoft.com/Guitar/

Thanks
Mike

May 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Jeff Nibler | last post by:
I'm trying to set the width of a textbox via a style sheet but it isn't working for Netscape 4.7 This is what the page looks like: <form> <input type="text" class="t1"> </form> This is...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
0
by: Steve | last post by:
where do we change/set the styles at? If I use a wizard I can choose things like corporate or sumi, but if I design it myself, I can't find the attribute for this. thnx
3
by: Brian Henry | last post by:
I have my styles.css file filed with the styles used for the site, now how would i specify a control to have a certain style id from that styles.css file in code? i thought mycontrol.style would...
3
by: sagar | last post by:
Hello everyone, I am developing a AJAX based IM application. I use javascript to dynamically generated small windows using nested <div> within the web-page. I use the following ways to set...
2
by: Sam | last post by:
Hi all I'm looking for a way to detect the background color of my internal webpage through a stylesheet. And so far, the only solution I find is to open the styles.css file and parse the...
8
by: Jeff | last post by:
ASP.NET 2.0 I'm wondering how to set the color of a visited HyperLinkField (the link text) in a GridView?? Here is the markup of the HyperLinkField I have problems with: <asp:HyperLinkField...
1
by: Jeff | last post by:
I tend to be a bit behind the times, sometimes a generation further that I want. So, I've been thing about the "*" selector. I've noticed that unlike body, it styles form fields and form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.