Javascript Archives - Coding Sharp

Javascript

Get outer html of html element using Jquery

Get outer html of html element using Jquery

Javascript
<div class='block'> <p class='paragraph'> This is the text inside the second element </p> </div> for an example if we consider above code block and write a code like below var htmlString = $("#paragraph").html(); then htmString can have a value "This is the text inside the second element" only now what if you want a result like "<p class='paragraph'> This is the text inside the second element </p>" Sometimes you will need the selected object as well, so below is a small jquery code block which will give you the complete html (outer html) of a Jquery selector. There are 2 different ways for that, we will see both There are two major methods used to get an objects outerHTML, we’ll be discussing both. Getting wrapper html using the ou...
Javascript setTimeout() Function with Examples

Javascript setTimeout() Function with Examples

Javascript
setTimeout() Function setTimeout() is a native JavaScript function. Which is allow us to call a specific JavaScript function or piece of code at specified interval or delay (on milliseconds). It might be useful when you want to display a message or a popup after user has browse the webpage for a certain amount of time. Simple example for setTimeout in above example, it will display an alert message after 2 seconds once you press ok button. Let's have a look at the syntax for setTimeout function timerId is a numerical id return by setTimeout function, so later we can use it to call clearTimeout function to cancel the timer. FunctionName - is the name of the JavaScript function to be executed after given interval. jscode - in place of js function you can give direct the ...
Creating and submitting a form using javascript

Creating and submitting a form using javascript

Javascript
In this article I will show you how to create a form dynamically using JavaScript and submit it. JavaScript provides a way to create a DOM element easily using createElement method. see the below code snippet for creating a form element using same method you can create other element as well see the below code which creates input element After creating form element you can set the action, method, target attributes of the form element as below. for filed element we need to set the name of the element and value of the element and need to add element to the form element as below after we add all the element to the form, we need to add form to the body of page and then submit the form as below That's it. Now see the below complete function for Creatin...