Categories
JavaScript

Jquery innerHTML HTML() function and text and tags manipulation between tags

  • $(‘#errors’).html(‘<p>There are four errors in this form</p>’); // Will put as the content in the div ‘errors’
  • $(‘#errors’).append(‘<p>There are four errors in this form</p>’); // Will append to the content in the div ‘errors’
  • $(‘#errors’).preppend(‘<p>There are four errors in this form</p>’); // Will prepend to the content in the div ‘errors’
  • $(‘#errors’).text(‘<p>There are four errors in this form</p>’); // Will escape HTML tags as HTML entities
  • $(‘#errors’).before(‘<p>There are four errors in this form</p>’); // Will put the code before the specified element.
  • $(‘#errors’).after(‘<p>There are four errors in this form</p>’); // Will put the code after the specified element.
  • $(‘#errors’).remove(); // Will remove the contents of errors
  • $(‘#errors’).replace(‘Brand new content!’); // Will replace the content of errors