Jquery id selector problem

  • 1
  • Question
  • Updated 5 years ago
I have a Custom Component with an id of cTest. However I can't access it with the jQuery id selector. The inline code is 

var element = arguments[0],
   $ = skuid.$;

element.html('Hello <b>world!</b>');      // This works ok
$('#cTest').html('Goodbye world');        // This does not work

What am I doing wrong?

Photo of Peter Baeza

Peter Baeza

  • 2,868 Points 2k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 48,984 Points 20k badge 2x thumb
At this point in the code, your Custom Component's element is not yet in the DOM, so jQuery cannot find it. Immediately after this Custom Component definition is finished, the element will be added to the DOM, and accessible via jQuery. Therefore, from within your Custom Component definition, you have to use the element variable, as this is the only way to get at the DOM element.