By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,521 Members | 1,274 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,521 IT Pros & Developers. It's quick & easy.

IMG Javascript question

P: n/a
So just started playing with Javascript, and my first run at making three
step buttons came out just fine. But I do have a general question.

In my book's example in the HTML script the IMG tags have the button's
settnigs for Width, Height, Border (0), and even grant each button an "id".

The "id" label is not used in the Javascript, so I was wondering if it and
the other items listed above MUST be in the HTML code, or does the book have
it in there just to be all proper like?

Many thanks
Jun 30 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
SAM
Daniel Kaplan a écrit :
So just started playing with Javascript, and my first run at making three
step buttons came out just fine. But I do have a general question.

In my book's example in the HTML script the IMG tags have the button's
settnigs for Width, Height, Border (0), and even grant each button an "id".

The "id" label is not used in the Javascript, so I was wondering if it and
the other items listed above MUST be in the HTML code, or does the book have
it in there just to be all proper like?
certainly in next pages of your book they will learn to you how to use
this ID in JS.

For the moment, notice that you can have only one ID of same name in a page
(2 or more identical ids is forbidden - the JS will have to be abble to
find the element (object?) by its ID, with several clones it will
retreive only the 1rst of them)


Of course, if these IDs are not used you can delette them
(be sure they are not used by CSS)
(take care your exercice will be used in next ones and probably there
the IDs will get sens)


width, height, border can be fixed by CSS.

Get used to write all your code (even in HTML) in lowercase
(Height -height - onMouseOver -onmouseover)
If the HTML is not case sensitive, the JS it is.

If you'll do :

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function hello() { alert('hello');}
  3. function init() {
  4. document.images[0].onClick = hello;
  5. }
  6. window.onload = init;
  7. </script>
that will not work because in JS it is : onclick


Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function hello() { alert('hello');}
  3. function init() {
  4. if(document.images && document.images.length>0)
  5. {
  6. document.images[0].omouseover = hello;
  7. }
  8. }
  9. window.onload = init;
  10. </script>
--
sm
Jun 30 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.