When developing a Windows Vista/7 Gadget, and putting out text using addTextObject(), this works:
var mytext = "Hello";
document.getElementById("background").addTextObject(mytext , "Verdana", 11, "white", 10, 10);
But I cant get this jQuery selector into a variable to work:
var mytext = $("#myid").text();
document.getElementById("background").addTextObject(mytext , "Verdana", 11, "white", 10, 10);
It doesn't work, it only writes an empty string. Why?
I found out why. The content in my div was added dynamically using jQuery.
<div id="myid"></div>
$("#myid").append("somedata");
var mytext = $("#myid").text();
System.Debug.outputString(mytext); // Empty
For some reason, this doesn't work in the Gadget. It does work in a plain HTML file though...
Static content do work in the Gadget:
<div id="myid">somedata</div>
var mytext = $("#myid").text();
System.Debug.outputString(mytext); // Ok
Can anyone explain how I can query dynamically added content in a Sidebar? UPDATE: This solved my problem.