javascript - jquery transform fails below parent level. Why? What do I do? -
The images should be wrapped with the following code, but this is not and I'm stumped. Could it be because I've used getJSOndata?
& lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Working with JSON & lt; / Title & gt; & Lt; Style & gt; # Content {padding: 5pt; Border: 2px dashed light; } & Lt; / Style & gt; & Lt; Script type = "text / javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ ("Document") ready (work () {getJSONData (); addDIV (); jQuery ('IMG', '# content'). Etr ("alt", "noddy");});
Call for images.
function getJSONData () {var FlickrAPI = "http://api.flickr.com/services/feeds/photos_public?gNEjsoncallback ="; $ .getJSON (Flickr API, {tag: "space needle", tagmode: "any", format: "jsnu"}, success fan); }
Create HTML for images. Function Success Fn (Results) {$. EE (Results. Items, Function (i, Item) {$ (Entry ({"src": item.media.m, "alt" : "Gallery"}) .adendo ("#content"); if (i === 4) {return lie;}})}}
An example of this problem is.
I can add a tag to parent (div)
but I can not add a tag to the child.
addDIV () {// to each image Put in your own // div / select all the images // it works in $ ('# content'). Rap ("& lt; div & gt; & lt ; / DIV & gt; "); // This $ ('#img IMG') does not work. Rap (" & lt; DIV> "); // Q ???} & lt; / script> & lt; / head & gt; & lt; body & gt; & lt; h1 & gt; working with different data types & lt; / h1 & gt; & Lt; div id = "content" & gt; & lt; / div> & lt; / body & gt; & lt; / html & gt;
You should run the addDIV function within the callback function successFn :
Function Success Fan (Results) {$. EE (Results.im, Function (i, Item) {$ ("& lt; Img & gt;) Attr ({"src": item.media.m, "alt": "gallery"}) .adendo ("#content"); if (i === 4) {return false;} }); AddDiv ();}
Be aware that using an Ajax request that is asynchronous by default, which means that Javascript execution will continue, even if The callback response has not been implemented yet, in the code below, addDiv () is being executed before the callback successFn () .
$ ("Document"). Ready (function () {GetJSOndata (); addDIV (); jQuery ('img', '#content'). Etr ("alt", "noddy");});
Comments
Post a Comment