0

In a complex loop that is getting data from Facebook I have to add a blank div with class name out side of an img tag.How do I do that.

//Currently it's like the following
<img src="img" id="imageID"></img>

//Need to get it to following using jQuery
<div class="className"> <img src="img" id="imageID"></img> </div>

//Script

$(#imageID).prepend("<div">).addClass("className").append(</div>");

1 Answer 1

2

You have to wrap the ID-Selector into string literals and should use $.wrap():

$('#imageID').wrap('<div class="className">');

Demo: http://jsfiddle.net/TimWolla/68L7d/

Sign up to request clarification or add additional context in comments.

1 Comment

Hi David,Thank for the answer but when I use the same concept to my project it's not working properly. The project can viewed at jsbin.com/adirus/9/edit Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.