Search code examples
jqueryhtmlqunit

Why is JQuery .html() returning null?


I have a QUnit test suite and am calling

 $('#idForElement').html();

inside a QUnit test (which is registered on $(document).ready(), and then run), but this function returns null in Chrome, Firefox and IE.

However, in the script tab of Firebug in Firefox, I am able to get the expected string by adding the code as a watch expression and can see a HTML element displayed on the page and in the HTML tab of Firebug.

I've read http://api.jquery.com/html/, I have assigned this into new var, an initalised string, put the result of $('#idForElement'); into a variable and called .html() on that, tried alerts in those browsers.

What's the next step to get this working?


Solution

  • Rookie error.

    Was calling $('#idForElement'), but setting the var to $('idForElement').

    It turns out you can append to an empty wrapped set.