Hi I’m trying to place a form below an image with a certain URL, however it’s not working. I’m not exactly sure
what I’m doing wrong since I’m new to JQuery. Would anyone happen to know what’s wrong with this?
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript">
function main(){
var imageURL = getImageURL();
$("img[src=imageURL]");
$("img[src='Your URL']").append("<input type="radio" name="geo" value="geolocation">Use Geolocation? <br> Additional Information About the Image: <input type="comment" name="cmnt">");
}
function getImageURL(){
var url = "http://www.w3schools.com/images/pulpit.jpg";
return url;
}
</script>
</head>
<body onload="main()">
<b> Page </b>
<img src="http://www.w3schools.com/images/pulpit.jpg">
</body>
</html>
A couple of problems. You can’t use the variable
imageURLcan’t be placed directly inside the src selector. You need to concatenate it in with+. Then, rather than.append()which adds to a given node’s child nodes you need to use.after()to add elements as sibling nodes to the selector.Rather than just a single
<input>you should be appending a<form>with the<input>nested inside it.