Friday, March 2, 2012

How to convert jquery object to string?

In jquery we can use .html() get the html code.
But how can we convert it to string?
That is very simple, we just asign the .html() to a javascript variable.

var v = $("#xxx").html();

The variable v will be change to a string that about .html() content.

DEMO


<html>
<body>
<div class="demo">
<h2>DEMO</h2>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function test(){
    var v = $("#asignHtmlToString").html();
    alert(v);
}
</script>
<button id="asignHtmlToString" onclick="test();">Click Me</button>
 </div>
</body>
</html>

Related Articles
jquery disable button

1 comment: