Link to home
Start Free TrialLog in
Avatar of Todd Penland
Todd PenlandFlag for United States of America

asked on

jQuery to Add Image from XML File

I've just about got this working (with the help of others here).  I'm new at using jQuery so please be patient.  Here's what I'm trying to do.

I have the URL for three images within <image> tags in my XML file (attached).  I now want to use jQuery to insert these images into my HTML page.  I know I need to set both the 'class' and the 'src' attributes in here somewhere but I can't quite manage to make it work.  I know the jQuery in my .js file (attached) is wrong however it works fine until it gets to inserting the images. Any help?  Thanks!
pbkpluscom-jquerytest.html
pbkpluscom-jquerytest.xml
pbkpluscom-jquerytest.css
pbkpluscom-jquerytest.js
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
more specifically this line, which has another issue you should be aware of. You should use double quotes to encapsulate the entire string and single quotes for strings within a string. if you only use the one type you'll run into problems as the system won't knew where a string starts and ends.

$('<img class='imgfloatr'>').html( $('image', this).html() ).appendTo('content');

needs to be

$("<img class='imgfloatr' src='+$('image', this).html() +'>").appendTo('content');
the .appendTo should reference an element but you've specified "content", which I can only find in the xml. this should be an element in your html, not the xml, such as "body"out another element such as a div with an ID. e.g. .appendTo("div#idhere")