views:

153

answers:

2

Hello:

I'm trying to add via jQuery the share icon [1]. Unfortunately I can't seem to do this as jQuery appears to escape the script code and I can't seem to get it to work with .text() or .html().

Has anyone gotten this, or something similar, working?

The code I'm trying is:

var enc = $('<div/>')
            .text('<script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=faa9f152-cae0-4ff3-bab7-32ae934bc698&amp;amp;type=website&amp;amp;style=ro
            ;

$('<div/>')
    .appendTo(nav)
    .addClass('navItem')
    .append(eval(enc))
    ;

[1] http://sharethis.com/

A: 

Use $.getScript(url, callback) for loading scripts at runtime.

The callback is triggered when the script is loaded.

Peter Gibson
A: 

Try adding html() at the end to first convert html tags to their entities eg:

var enc = $('<div/>')
        .text('<script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=faa9f152-cae0-4ff3-bab7-32ae934bc698&amp;amp;type=website&amp;amp')
.html();

More Info Here: http://debuggable.com/posts/encode-html-entities-with-jquery:480f4dd6-13cc-4ce9-8071-4710cbdd56cb

Sarfraz