William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

jQuery examples summary 3

Continue the jQuery examples summary, the examples mainly from http://api.jquery.com/

//1. after()
var $newdiv1 = $('<div id="object1"/>'),
  newdiv2 = document.createElement('div'),
  existingdiv1 = document.getElementById('foo');
$('p').first().after($newdiv1, [newdiv2, existingdiv1]);

  .filter('p').attr('id', 'bar').html('hello')
$("p").after( $("b") );

//2. insertAfter( target )

//3. before( content, [ content ] )
$("p").before("<b>Hello</b>"); $("p").before( document.createTextNode("Hello") );
$("p").before( $("b") );

//4. insertBefore( target )
$("input[type=password]").before(function() {console.log(this);});

What is the difference between insertAfter() and appendTo()?

  • insertAfter() inserts an element AFTER another element,
  • While .appendTo() insert elements INTO another element

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: