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.
Ho开发者_开发百科wever, 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?
It may depend on when you are calling this function. If you do this before the document.ready event, the element may not exist yet. Try wrapping your code like this:
$(document).ready(function () {
//your code goes here
});
Rookie error.
Was calling $('#idForElement')
, but setting the var to $('idForElement').
It turns out you can append to an empty wrapped set.
精彩评论