-1

Using the latest version of the FireFox (40.0.3) on Mac:

Run the following code:

$(function() { 
        var $sc = $('<script id="tempScript" type="text/template"/>');  
        $("body").append($sc);
        $("<div><h3>Hi</h3></div>").appendTo($sc);
});

Then in the console run:

$("#tempScript").html()

Actual result: result is "undefined"

Expected result: It should have returned: "<div><h3>Hi</h3></div>"

This is very serious problem and has effected a lot of our web applications functionality. Basically has broken a lot of pages of our applications.

Is there a workaround for this? We would have to use Javascript to generate the dynamic content.

UPDATE: I changed the script tag to a hidden DIV and Firefox started to respond. This is a good workaround for the time being, but I am surprised why Firefox would not handle the situation correctly when script template is used.

sam360
  • 1,121
  • 3
  • 18
  • 37
  • Did you mean to use this function `$.getScript(url, callback)`? – Popnoodles Sep 22 '15 at 16:25
  • `#tempScript` is a script tag. Why do you think `.html()` would return anything? – Popnoodles Sep 22 '15 at 16:27
  • First of all it works the same way on Div tags too, secondly I am specifying the type of "text/template" which is a common use case for HTML 5 templates. – sam360 Sep 22 '15 at 16:28
  • 3
    but your script tag is empty - it can't return any html.. – gulty Sep 22 '15 at 16:29
  • 2
    Also, ` – neilsimp1 Sep 22 '15 at 16:29
  • 1
    @neilsimp1 jQuery deals with that, it's not an issue. – Popnoodles Sep 22 '15 at 16:30
  • 1
    I think you're after `$sc.append( $("

    Hi

    ") );` or `$sc.append("

    Hi

    ");` => [http://jsfiddle.net/2qvgwdvj/](http://jsfiddle.net/2qvgwdvj/)
    – lshettyl Sep 22 '15 at 16:30
  • 1
    @sam360 not that tag - it's an empty tag that you've appended. It has no content so `.html()` **should** return undefined. – Popnoodles Sep 22 '15 at 16:31
  • @Popnoodles works perfectly in Chrome and Safari! and I am appending the content to the script tag correctly! – sam360 Sep 22 '15 at 16:33
  • 2
    You're appending the script tag (moving it from body) to `$("

    Hi

    ")` which doesn't have any reference by which you can get it back. **Edit** no, you went and fixed that part of the question. Any more typos in there?
    – Popnoodles Sep 22 '15 at 16:34
  • @Popnoodles That's cool, I didn't know that – neilsimp1 Sep 23 '15 at 15:45

1 Answers1

0

Turns out Firefox does not handle dynamically added script text/template tag and cannot return its HTML content in Javascript (Chrome and Safari work fine).

I changed the script tag to a hidden DIV and Firefox started to respond. This is a good workaround for the time being, but I am surprised why Firefox would not handle the situation correctly when script template is used.

sam360
  • 1,121
  • 3
  • 18
  • 37