Jump to content

Best practice?


carinemaz
 Share

Recommended Posts

I'm still in the process of learning Javascript, and want to learn it using the best practice. So it seems inline elements are not the way to go...I've been working on an image map, and all works, thanks to the help of some of you, but I'd like to get rid of the inline elements "onmouseover" and "onmouseout"... And have my code in an external sheet.Is it possible in this example? Would anyone be willing to show me how to create such a code?The code is a little long, so here is the linkhttp://www.medipsy.com/medecin/implantation.phpThanks in advance for any help or suggestions!

Link to comment
Share on other sites

You will need to give the <a> an id then do this

var obj = document.getElementById('elementId');obj.onmouseover=function(){cut and paste the inline code here}obj.onmouseout=function(){cut and paste the inline code here}

This is an easy way to get rid of inline javascript. :) Hope it helps

Link to comment
Share on other sites

Thank for the code, but....hum.... :) Been trying to get it to work, but can't figure it out...I know I'm doing something wrong but don't know what?

<script type="text/javascript">var obj = document.getElementById('elementId');obj.onmouseover=function(){onMouseOver="writeText('Moulin')"}obj.onmouseout=function(){onMouseOver="writeText(' ')"}</script></head><body><a id="test" href="#">test</a> <p id="desc"></p></body>

I've tried with and without the onmouseover between the {} but doesn't make a difference...

Link to comment
Share on other sites

Thank for the code, but....hum.... :) Been trying to get it to work, but can't figure it out...I know I'm doing something wrong but don't know what?
<script type="text/javascript">var obj = document.getElementById('elementId');obj.onmouseover=function(){onMouseOver="writeText('Moulin')"}obj.onmouseout=function(){onMouseOver="writeText(' ')"}</script></head><body><a id="test" href="#">test</a> <p id="desc"></p></body>

I don't know much JavaScript myself, but I think you have to replace "elementId" in the brackets with the actual target of the script, which in this case is... test, right?
Link to comment
Share on other sites

<script type="text/javascript">var obj = document.getElementById('elementId');obj.onmouseover=function(){onMouseOver="writeText('Moulin')"}obj.onmouseout=function(){onMouseOver="writeText(' ')"}</script></head><body><a id="test" href="#">test</a><p id="desc"></p></body>write the id of the <a> in the place of the bold text, try this....var obj = document.getElementById('test');

Link to comment
Share on other sites

</head><body><a id="test" href="#">test</a><p id="desc"></p><script type="text/javascript">var obj = document.getElementById('test');obj.onmouseover=function(){writeText('Moulin')}obj.onmouseout=function(){writeText(' ')}</script></body>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...