abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

5/01/2018

JQUERY with HTML & CSS

hi,

main difference between text & html method

Sometimes, i think both are same to set or return the html content. But, the jQuery text() method is different from html() method.
Following is the main differences:
  • The jQuery text() method is used to set or return html content without HTML markup while, html() method is used to set or return the innerHtml (text + HTML markup).
  • The jQuery text() method can be used in both XML and HTML document while jQuery html() method can not.

syntax are three ways,
$(selector).text();
$(selector).text("abcd");  
$(selector).text(function(index,currentcontent)) ;

if you look above syntax there are difference in all syntax ,
 above first syntax is use for return or get text content in html tag.
second syntax is use for set content in html tag
& third is using function.
 

    an example of html & jquery
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.     $("button").click(function(){  
  8.         $("p").text("hi abc!");  
  9.     });  
  10. });  
  11. </script>  
  12. </head>  
  13. <body>  
  14. <button>hi click me</button>  
  15. <p>Hello Guys!</p>  
  16. <p>Looking for online training....</p>  
  17. </body>  
  18. </html> 
try code & run in browser you can view output.

similarly html method happen but it change all entire content.
  1. $(selector).html()
  2. $(selector).html(content)
  3. $(selector).html(function (index, currentcontent))


<!DOCTYPE html> 
<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
<script> 
    $(document).ready(function(){ 
        $("button").click(function(){ 
            alert($("p").html()); 
        }); 
    }); 
    </script> 
</head> 
<body> 

<button>Return the content of p element</button> 

<p>
This is first <b>paragraph</b>.</p>
<p>
This is another <b>paragraph</b>.</p>
</body> 
</html> 






in next session we view more method such as before() , prepend(), append(), empty(), detach(), scrolltop(), delay()

1 comment:

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...