6

In the jQuery Infinite Carousel, it uses .clone() to do the infinite effect. This works great unless the code it's cloning has HTML5 Elements. IE7 and IE8 have trouble applying HTML5 Element-specific CSS rules to cloned or otherwise post-page-load inserted elements.

The innerShiv JavaScript plugin inserts the elements in a way that IE7 and IE8 will render just fine with the appropriate CSS.

The problem is that innerShiv takes an HTML string as a parameter, but the jQuery .clone() method returns an array of jQuery objects.

In order to use the two together, I need to convert the output from .clone() into an HTML string that innerShiv will be able to parse.

Any thoughts on how this could be done?

1
  • 3
    just call .html() on the objects? Commented Mar 17, 2011 at 17:02

3 Answers 3

8

HTML:

<p class="foo"><canvas class="bar"></canvas></p>

JavaScript: [Ref]

// grab the object, with HTML 5 element(s).
var p = $('p');

// clone it
var c = p.clone();

// grab the inner html (wrap it so we can get the HTML)
var html = $('<div>').append(c).html();

// alert us of the contents
alert(html);

Demo:

http://jsfiddle.net/bradchristie/tDFYn/

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

Comments

1

Use .clone().html();, it will convert the objects to a string. Take a look: http://jsfiddle.net/9k2LS/

-edit-

Reconsidered: Indeed @Jazzerus, why use .clone()? .html() without clone() will do.

1 Comment

.html() without .clone() won't technically do as .clone duplicates the current object and ancestors. .html() is only the code for the ancestors.
1
var html = $.parseHTML(yourHtmlString); //Returns an Array of HTML Objects

//some operations on html like $(html).find() ...

html  = $('<div>').append(html).html();  // Returns string (string of html)
console.log(html);

1 Comment

You should consider adding an explanation of the solution you're proposing.

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.