Reputation: 8285
I have a div
<div id="dialog-confirm-error-validating-choices" title="Pop up">
<p><span class="floatLeft"></span>
<p id="error-message"></p></p>
</div>
that I select with jQuery and I put it into a variable
var messageDialog = $('#dialog-confirm-error-validating-choices');
I want to set the inner html of an element within this variable
messageDialog.filter('#error - message').innerhtml("Hello");
Is this how it is done? Can it be done?
Upvotes: 1
Views: 80
Reputation: 20220
Considering the element you're looking to select has a unique ID, the most efficient selector would be its ID:
$('#error-message').html('hello');
Upvotes: 0
Reputation: 337560
Try this:
var $messageDialog = $('#dialog-confirm-error-validating-choices');
$messageDialog.find('#error-message').html("Hello");
// alternative: $('#error-message', $messageDialog).html("Hello");
Note that innerHtml
is the method to change the HTML of a plain javascript element, whereas for a jQuery object you need to use the html()
method. Also, the convention is to prefix variables which contain jQuery objects with a $
.
Upvotes: 2
Reputation: 5917
Try this.
$('#error-message').html("Hello")
Note that the function html
sets the html
Also note that I updated your query, to match the id of the element
Upvotes: 0