Search

Thursday, June 11, 2015
0 comments

How to get Elements of HTML using id and class in JQuery

9:07 AMThursday, June 11, 2015
How to get the element from the html file using their id and class property. In my previous article we have already get the html element from their id property. But in this article we will get the element from their class name. Lets take a simple example to demonstrate the article.

<%@ Page Language="C#" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script src="Scripts/jquery-1.10.2.js"></script>
<script>
$(function(){
$('#Button1').click(function () {
var firstdiv = $('#first').html();
alert(firstdiv);


var getclass = $('.test').html();

alert(getclass);

});


})
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="first" style="border: 1px solid #009900; padding: 10px">
    Welcome to my website
    </div>

<div style="border: 1px solid #00ffff; padding: 10px" class="test">

Get This Text By class
</div>
<input id="Button1" type="button" value="Get Element By Id" />
    </form>
</body>
</html>
When we click on the button a alert message have to generate with some message. Using html () method we can get the text of the tag.

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top