carinemaz Posted April 30, 2006 Share Posted April 30, 2006 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 More sharing options...
aspnetguy Posted May 1, 2006 Share Posted May 1, 2006 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 More sharing options...
carinemaz Posted May 1, 2006 Author Share Posted May 1, 2006 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 More sharing options...
boen_robot Posted May 1, 2006 Share Posted May 1, 2006 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 More sharing options...
pulpfiction Posted May 1, 2006 Share Posted May 1, 2006 <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 More sharing options...
carinemaz Posted May 1, 2006 Author Share Posted May 1, 2006 That's what I did at first, but since it wasn't working, I assumed I had to leave the elementID ....Even more confused now! Link to comment Share on other sites More sharing options...
aspnetguy Posted May 1, 2006 Share Posted May 1, 2006 </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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now