Jquery Get Content

Jquery text()
This helps to return the text content of selected element.

Code Structure
$(document).ready(function(){
 $('button').click(function(){
  alert($('.test').text());
 });
}); 

Jquery html()
This helps to return the text and HTML content of selected element.

Code Structure
$(document).ready(function(){
 $('button').click(function(){
  alert($('.test').html());
 });
}); 

Jquery val()
This helps to return the value of form field.

Code Structure
$(document).ready(function(){
 $('button').click(function(){
  alert($('#input').val());
 });
}); 

Jquery attr()
This helps to return the value of href attribute in a link.

Code Structure
$(document).ready(function(){
 $('button').click(function(){
  alert($('#link').attr('href'));
 });
}); 

Share this

Related Posts