For loop or foreach in jQuery

Thursday, January 26, 2012

0 comments
Just add reference to the jQuery library and execute the below script.
I have read all text inside the list tag.

<script>
$(document).ready(function(){

$("li").each(function(){
alert($(this).text());
});

});
</script>

<ul>
<li>testers</li>
<li>test</li>
<li>testing</li>
<li>coding</li>
<li>Internal</li>
</ul>

Microsoft JScript runtime error Function expected

0 comments
If you get the error "Microsoft JScript runtime error Function expected" then there will surely some JavaScript syntax problem. Just check all the tags closed properly.

getElementsByClassName using JavaScript

0 comments
<script type="text/javascript">
function Readall()
{
var currSelected = document.getElementsByClassName("clsSample″);

for (var i = 0; i < currSelected.length; i++)
{
alert(currSelected[i].value);
}
}
</script>

<div>
<input class="clsSample" id="txt1″ value=" type="text" />
<input class="clsSample" id="txt2″ value=" type="text" />
<input class="clsSample" id="txt3″ value=" type="text" />
</div>

Get browser screen width and height using jQuery

0 comments
You can get the width and height of the browser using the window object in jQuery. It will return the current browser document or window height and width.

var ScreenWidth = $(window).width();
var ScreenHeight = $(window).height();

Get and set value for hidden field using jQuery

0 comments
You set the value to the hidden fields and also get the value from it using the jQuery. The below script helps to get and set value to the hidden field in jQuery.

<input type="hidden" id="hdnSample" />

Set value to hidden field:

$("#hdnSampleval('test data');

Get value from hidden field:

var hdnValue = $("#hdnSample").val();

How to close jQuery dialog

0 comments
The below method helps to close the jQuery dialog.

$("#dialog").dialog("close");

Find which element have focus using JavaScript

0 comments
You can find currently which element have focus or active element using the JavaScript.

var ActiveElement = '';
ActiveElement = document.activeElement.tagName;