Please can anyone explain what this javascript code exactly does.
$('#element_id').html(response.title);
I need to access the value of the element_id but I can't using document.getElementById.
Thanks
Please can anyone explain what this javascript code exactly does.
$('#element_id').html(response.title);
I need to access the value of the element_id but I can't using document.getElementById.
Thanks
This code just calls a function named $
and access a method of the returned object.
It's probably jQuery code due to the selector string.
$('#element_id')
: Returns a jQuery object for the element with the given ID..html(response.title)
: Sets the inner HTML of the DOM element to response.title
.The raw JavaScript would look like this:
document.getElementById("element_id").innerHTML = response.title;
$ probably refers to jQuery, one of the most frquently used JS libraries.
What this snippet basically does is setting the HTML content of the element with the id element_id to the title attribute of the response object.
It looks like jQuery, which is a Javascript library. The $('#element_id')
creates a jQuery object for the element with the id element_id
in the DOM. Then .html(response.title)
will put the value of response.title
as HTML inside the element.