Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

jQuery: Create Parent for Element

Using jQuery, how can I put #world INSIDE #hello?

I want to create a div with an id of "hello" around this:

<p id="world"></p>

Open in new window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function() {
 alert('Create div with id of hello and place #world inside it');
 //  <div id="hello"><p id="world">Foobar/p></div>
});
</script>

</head>
<body>

<p id="world">Foobar/p>

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of varontron
varontron
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial