This is my first jQuery program and boy am I having trouble. My first question: when I am trying to load images should I have the images separate in the root folder? I am trying to load five images with "title" to them and mouseenter and mouseleaving for them. At first I had all the images separate in the root folder but I also made a xml file with the images and titles in it. I just do not know. I also don't know if I have my HTML file done correctly. Could someone please explain this to me. I would really appreciate it and thank you. I have my images saved as "img1.png" and so on.Here is my code. I am sure that I probably have a mess of it. <!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js> </script> <script> var img = new Image(); $(document).ready(function(){ $("img").load(file///C:/inetpub/wwwroot/pictures.xml) { $("#img1").mouseenter(function(){ $("#p1").css("background-color","yellow"); } $("#img1").mouseleave(function(){ $("#p1").css("background-color","lightgray"); } $("#img2").mouseenter(function(){ $("#p2").css("background-color","yellow"); } $("#img2").mouseleave(function(){ $("#p2").css("background-color","lightgray"); } }; </script> </head> <body> <p1>Roman Numeral One</p1> <p2>Roman Numeral Two</p2> //<p3>Roman Numeral Three</p3> //<p4>Roman Numeral Four</p4> //<p5>Roman Numeral Five</p5> </body> </html> HTML:
Okay, first of, there are no <p1> <p2> etc html elements. It's <p> - no numbers. And you select each of them by traversing the DOM, or add an ID to each element. Second, I'm not entirey sure what you wanna do - you have no images present in your code - do you want to load an image on mouseover? Or...?
Yes, but load them how - do you just want them on your page? If so, why not just code them into the page in HTML. Or, do you want a javascript that loads any amount of pictures into a page? Or, are you wanting the images to only show/load when a user hovers over them? You need to be a bit more specific.
OK I am trying replace the ajax calls in the program with jQuery. Can someone explain to me how to do this. Please and Thank You <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript"> var request; function getContent(url) { request = new XMLHttpRequest(); request.onreadystatechange = stateChange; request.open("GET", url, true); request.send(null); } function stateChange() { if (request.readyState == 4 && request.status == 200) { document.getElementById("content").innerHTML = request.responseText; } } function clearContents() { document.getElementById("content").innerHTML = ""; } </script> </head> <body> <header> <h1>AJAX</h1> </header> <img src="one.png" onmouseover="getContent('one.html')" onmouseout="clearContents()" /> <img src="two.png" onmouseover="getContent('two.html')" onmouseout="clearContents()" /> <img src="three.png" onmouseover="getContent('three.html')" onmouseout="clearContents()" /> <img src="four.png" onmouseover="getContent('four.html')" onmouseout="clearContents()" /> <img src="five.png" onmouseover="getContent('five.html')" onmouseout="clearContents()" /> <div id="content" style="border: 1px solid black; padding: 10px"> </div> </body> HTML:
My question on the code in the first post would be why are you using javascript to do CSS' job? As to the second one, why are you pissing away accessibility with script-tard ajaxtardery? Pageloads aren't evil.... much less the headache of hover states mated to show/hide Ajax, something that REALLY shouldn't EVER be done on a website in the first place.