Monday, 23 January 2012

java script createTextNode() Method,assign() Method in JavaScript,link() Method in JavaScript, slice() Method java script

createTextNode() Method
The createTextNode() method creates a text node. This method returns a Text object.
Example:
<html>
<body>
<script language="JavaScript">
function fnct_node() {
   var my_node = document.createTextNode("Good Morning!!!");
   document.body.appendChild(my_node); 
} 
</script>
<button onclick="fnct_node()">Create text node</button>
</body>
</html>
Output:

pow() Method
The pow() method returns the value of x to the power of y .
Example:
<html>
<body>
<button onclick="alert(Math.pow(2,2));">POW</button>
</body>
</html>
Output:





blure() and assign() Method in JavaScript
blure() Method in JavaScript
The blur() method is used to remove focus from an element.
Example: Take a example to loss the focus of Button.
<html>
<body>
<script language="JavaScript">
function remove_focus(){
   document.getElementById("removeButton").blur();
   document.getElementById("removeButton").innerText = "This button lost its focus";
   alert("The button lost its focus"); 
} 
</script>
<input id="removeButton" 
       type="button" 
       onclick="remove_focus();" 
       value="Input Focus" 
       onFocus="this.innerText='In focus. Click me to lose focus'">
</body>
</html>
Output:




assign() Method in JavaScript


The assign() method loads a new document.
Example:
<html>
<body>
<script language="JavaScript">
    function new_doc() {
        location.assign("http://r4r.co.in/");
    }
</script>
<input type="button" value="Load new page(R4R)" onclick="new_doc();">
</body>
</html>
 
 

Output:






link() Method in JavaScript


The link() method is used to display a string as a hyperlink. This method returns the string embedded in the <a> tag, like this: <a href="url">string</a>

Syntax:
string.link(url);


Example:
<html>
<body>
<script language="javascript">
function new_url()
{
var myS = new String('r4r.co.in Home Page'); 
document.write(myS.link('http://www.r4r.co.in/'));
}
</script>
<button onclick="new_url()">Create a link from</button>
</body>
</html>
Output:





slice() Method

The slice() method extracts a part of a string and returns the extracted part in a new string.

 

Syntax:
string.slice(begin,end)



Example:
<html>
<body>
<script>
function slice_string()
{
var myName = new String('Aditya Tiwari'); 
   alert(myName+'\n'+"After Slice="+ myName.slice(1,6));
}
</script>
<button onclick="slice_string()">Slice of Name</button>
</body>
</html>
Output:

Post a Comment