Skip to content

All topics  /  jQuery

How to Get the Tag Value or Element Content in jQuery ?

jQuery ·

Hi Dev,

In this blog, I will learn you how to get the tag value or element content in jquery. We get the tag value or element content from a selected tag.

You can get tag value in html using jquery then use bellow solution. Many way to you can get html tag value or element content.

Solution 1 : Select a tag of ‘p’ and display tag value.


$('p').html();

Solution 2 : Select tag has a class name of “test” and display its value.

$('.test').html();

Solution 3 : Select tag has a id name of “test” and display its value.

$('#test').html();

Full Example

<html>
<head>
    <title>Get Tag Value or Element in jQuery</title>

 
    <script type="text/javascript" src="jquery-1.3.2.js"></script>

 
</head>
<body>
    <h1>Get Tag Value or Element in jQuery </h1>
    <p>
        This is example 1
    </p>

	
    <div class="myClass">
        It is class='myClass'
	</div>

	
    <div id="myId">
        This is id='myId'
    </div>
    <script type="text/javascript">

 
        $(document).ready(function(){
            var $tag = $('p').html();
            alert($tag);

    
            var $tag = $('.myClass').html();
            alert($tag);

    
            var $tag = $('#myId').html();
            alert($tag);
        });
    </script>
</body>
</html>

It will help you...