Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this jQuery example?

The following jQuery example should put some text into the div, but it doesn't. I tried Firefox, Google Chrome and Internet Explorer.

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" language="javascript"></script>
<script language="javascript">

$(window).load(function() {

  $('adiv').html('<p>hello world</p>');
  alert('done');

});
</script>
</head>

<body>
<div id="adiv">
</div>
</body>

</html>

Sorry, this might be stupid, but I'm stuck.

like image 387
Sven Larson Avatar asked Dec 28 '22 19:12

Sven Larson


2 Answers

change $('adiv').html('<p>hello world</p>');to

$('#adiv').html('<p>hello world</p>');
like image 167
zer0w1dthspace Avatar answered Jan 05 '23 07:01

zer0w1dthspace


You're not actually selecting anything in your select function

Directly after your $( opening, you need to use a CSS3 valid selector. Just a string won't select anything unless it's a HTML element (table, div, h2)

You need to preface it with a . or a # to signal either a class or ID name.

like image 43
Alex Mcp Avatar answered Jan 05 '23 08:01

Alex Mcp