jQuery: use of wrap() on <img> element

html:

<img src="http://webmuseum.mit.edu/mobiusicons/no_image.jpg" />

css:

div.border
{
border: 2px solid #ccc;
width: 500px;
height: 500px;
}

js:

$("img").wrap('<div class="border" />');

This is my first time using the jquery wrap(). I was expecting to see the following

<div class="border"><img src="http://webmuseum.mit.edu/mobiusicons/no_image.jpg" /></div>

but wrap() didn't change anything and I got no error. Please help. Thanks.

Answers


Your code is working absolutely fine for me. See http://jsfiddle.net/trott/9Nm3M/.

(Try changing the border thickness to 20px for confirmation if you're not sure that it's working.)

Perhaps you aren't loading jQuery or something like that?


Have you included <script type="text/javascript" src="jquery.js"></script> in your head section. Check where it is loaded or not.. follow these: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery http://docs.jquery.com/Downloading_jQuery

check this jsFiddle and it is working correct with your code..


Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.