1

I have already found some question of this genre but the answer didn't help.

Javascript - div content without innerHTML

Javascript: Does not change the div innerHTML

I have a div called adx-title by id and i have to change the content. So i made my ajax call and i stored (i use jQuery) in a call the title i want this div to contain:

$('#adx-title').inneHTML = title;

Firebug report this ($('#adx-title').inneHTML) as undefined, and it does report so in every attempt i make to change the content of the div, which is read as an object but it doesn't have the innerHTML property. The script is loaded after i click a button so it should recognize the div as already loaded by the page. And indeed it gets the div with $('#adx-title'). it just doesn't apply the change and reports innerHTML as undefined. Anyone has had a similar issue? Anyone can help? Thanks Agnese

Community
  • 1
  • 1
softwareplay
  • 1,379
  • 4
  • 28
  • 64

2 Answers2

4

You're using jQuery.

$('#adx-title').html( title );

The .innerHTML property is part of the DOM API. When you make a call to jQuery (as you're doing with the $) the result is a jQuery object, not a DOM element.

You can get the DOM element from the jQuery object like this:

var elem = $('#adx-title').get(0);

However, the jQuery .html() API wraps access to the .innerHTML property and also provides some other useful bookkeeping features. If you're using jQuery in general to manipulate the DOM, it's a good idea to use .html() and not the raw DOM API for that reason.

Pointy
  • 405,095
  • 59
  • 585
  • 614
3

Try $('#adx-title').html(title);

Dmitry Igoshin
  • 111
  • 1
  • 3