Skip to Content
Introducing .NET 4.0: with Visual Studio 2010
book

Introducing .NET 4.0: with Visual Studio 2010

by Alex Mackey
February 2010
Beginner content levelBeginner
400 pages
11h 13m
English
Apress
Content preview from Introducing .NET 4.0: with Visual Studio 2010

12.4. Writing Elements Dynamically

jQuery allows you to easily insert elements on a page. The following code appends a <p> tag to the <div> with an id of div1:

<script>$("<p>hello I am dynamically added text</p>").appendTo("#div1")</script>

You can also insert an element after the target element with the .insertAfter() method:

<script>$("<p>hello I am dynamic text</p>").insertAfter("body")</script>

Remember that adding elements dynamically works slightly differently in IE than in Firefox. While researching this chapter, I was playing around with the following script:

<script>$("<p>hello I am dynamic text</p>").appendTo("body")</script>

This works fine in Firefox but will give you a strange error when run in IE 7 (see Figure 12-3). Can you guess ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

ASP.NET 3.5 For Dummies®

ASP.NET 3.5 For Dummies®

Ken Cox
ASP.NET 4 Unleashed

ASP.NET 4 Unleashed

Stephen Walther, Kevin Hoffman, Nate Dudek

Publisher Resources

ISBN: 9781430224556Purchase book