Tuesday, March 20, 2012

jQuery to get value of a Span element , using .html()

If a span element like below has to be read in jquery then .html() function comes to the rescue .

//in the jsf code 
 <h:outputText value="100.12"  styleClass="resOutputMaxTeor">

// in html
<span class="resOutputMaxTeor">100.12</span>

in the script read the span value using .html() function .

var max =  jQuery(".resOutputMaxTeor").html();

If it is a DOM element it can be read using .get() function

var max = jQuery(".resOutputMaxTeor").get(0) ;