Reputation: 15414
I have a variable that contains a bunch of HTML that I retrieve from a HTML5 SQL database.
I can .append()
this to an element in the DOM and it appears fine. But I want to .wrap()
the HTML contents first, thus I have written:
content = $(content).wrap(function() {
return '<div class="event_holder" />';
});
$('#mydiv').append(content);
However, I get the error
Syntax error, unrecognized expression: ~HTML contents of variable~
I have also tried:
content = $(content).wrap('<div class="event_holder" />');
Would anyone know whats going on here and how I can correctly wrap this?
EDIT: the contents of 'content' is:
<input id="e1coords" class="coords" name="e1coords" type="hidden" value="-27.482359,153.024725">
Upvotes: 0
Views: 5405
Reputation: 388316
The problem could be content = $(content).wrap('<div class="event_holder" />');
still returns the inner content not the wrapped element, you need to append the parent of the content.
Try
content = $(content).wrap('<div class="event_holder" />').parent();
Demo: Fiddle
Upvotes: 3
Reputation: 15414
I found out the because the content
variable was actually retrieved from a (html5) database it was not part of the DOM, thus JQuery was having issues with it.
I did the wrap manually and it worked
content = '<div class="event_holder">' + content + '</div>';
Upvotes: 0
Reputation: 36531
i don't know why are you using callback of wrap()
when you can do it directly
content = $(content).wrap('<div class="event_holder" />');
and it will be better if you can show us what actually the content
contents..
updated
try this
content = $('#e1coords').wrap('<div class="event_holder" />');
OR
var content = $('#e1coords');
content = content.wrap('<div class="event_holder" />');
Upvotes: 0