Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot set jquery dialog.InnerHtml(some-content) without refreshing the page

In my JS file, I am trying to set the content to a poped up dialog. In firebug, I saw the dialog opens and it hangs even after I set the content of it by $(dialog).InnerHtml. But this works when I refresh the page.

Any particular reason for this behavior?

like image 365
Subash Chaturanga Avatar asked May 18 '12 06:05

Subash Chaturanga


2 Answers

You cannot set .innerHTML directly off the jQuery object. You need to set $.html() instead.

// jQuery doesn't have an innerHTML property, so this is wrong
$("#dialog").innerHTML = "This is the wrong way";

// jQuery has an html() method that sets the html within your dialog
$("#dialog").html( "And this is the correct way" );

Keep in mind that when you're dealing with jQuery, you're dealing with an object, and not an element. Attributes like .innerHTML exist on elements within the DOM, but not within the jQuery object. jQuery provides methods like $.html() so that you don't have to ever touch .innerHTML.

like image 105
Sampson Avatar answered Oct 04 '22 05:10

Sampson


This is the way to do:

In javascript:

document.getElementById('dialog').innerHTML = 'something';

In Jquery :

$("#dialog").html('something');
like image 22
Vimalnath Avatar answered Oct 04 '22 05:10

Vimalnath