I can not figure out how to use the OnMouseOver event to hover the mouse over any documenta image to read (get) (SCR) the URI of this image and assign this URL to a variable. Well, then I like it myself. If you can help with this javascript code.

    3 answers 3

    <img id="ShowMeYourSRC:)" src="/img/someImg.jpg"/> <script type="text/javascript"> onload = function() { document.getElementById("ShowMeYourSRC:)").onmouseover = function() { alert(this.src) } } </script> 

    UPD

    If it is out of sight, for example, something like this

     onload = function() { alert("src картинки - " + document.getElementById("ShowMeYourSRC:)").src) } 

    Those. for example, to write src images with id "ShowMeYourSRC :)" to a variable

     onload = function(){ var src = document.getElementById("ShowMeYourSRC:)").src; alert(src); } 

    PS: in order not to get lost in the bases of the language I advise you to read this book.

    • Although I did not fully formulate the question you suggested the most successful, and most importantly, working code - commonodessit
    • To accept the answer, click the check mark on top just to the left of the question :) - Zowie
    • Your script turned out to be suitable, working, however, I unexpectedly ran into the problem of transferring the value of a variable, and I couldn’t override it for how long it was to save the value and transfer it to another script that exposes a new image when pointing to an image. defined as this.src already outside the scope of the function you are proposing loses its value. I give up, I can not carry out its transfer. Is it even possible? Already tried that script to put in the body of the function proposed by you in the script, it still does not work. - commonodessit

    This is wrong, wrong:

    html:

     <img onmouseout="onmouseimgoverorout(event)"> 

    and for other events, too, use

     `onmouseimgoverorout(event)` 

    javascript:

     function onmouseimgoverorout(evt){ var evet; var imgobj; if(window.event){ evet=window.event.type; imgobj=window.event.srcElement; } else{ evet=evt.type; imgobj=evt.target; } if(evet=="mouseover"){ //Когда mouseover } if(evet=="mouseout"){ // Когда mouseout } //imgobj это ваша картинка } 
    • Is this your right? xD - Zowie
    • Exactly what xD) roll a whole function in order to find out the src image) - Palmervan
    • Since it came to the creation of such a function, they would have onmouseout="onmouseimgoverorout(event)" how to properly hang an event, otherwise onmouseout="onmouseimgoverorout(event)" is somehow non-kosher. - ling
     <img src="..." onmouseover="x=this.src;" > 

    The variable x store the image address.