Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery not working to change inner html?

Tags:

jquery

hey people I'm new at jquery and i have been trying to figure this out for like the past couple of hours... what the hell am I doing wrong here? All I want to do is change the innerHTML of a div.

$("left_menu_bar").innerHTML = "You clicked me!";

but the div doesn't change at all when I call the function with that code init.

like image 371
GarryRig Avatar asked Apr 02 '12 16:04

GarryRig


People also ask

How to change inner HTML JavaScript?

To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.

How do you replace an element with another in jQuery?

We can replace HTML elements using the jQuery . replaceWith() method. With the jQuery replaceWith() method, we can replace each element in the set of matched elements with the provided new content and return the set of elements that were removed.

What is HTML method in jQuery?

The html() Method in jQuery is used to set or return the innerHTML content of the selected element. Syntax: It returns the content of first matched element. $(selector).html() It sets the content of matched element.

What is innerHTML?

The Element property innerHTML gets or sets the HTML or XML markup contained within the element. To insert the HTML into the document rather than replace the contents of an element, use the method insertAdjacentHTML() .


1 Answers

Do it like this:

// referencing by id
$("#left_menu_bar").html("You clicked me!");
// referencing by class name ( will apply to all div's with this class )
$(".left_menu_bar").html("You clicked me!");

http://api.jquery.com/html/

like image 142
Willem D'Haeseleer Avatar answered Sep 18 '22 13:09

Willem D'Haeseleer