Input URL placeholder Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input URL

Description

The placeholder property sets or gets the value of the placeholder attribute of a URL field.

This property reflects the HTML placeholder attribute.

Set the placeholder property with the following Values

Value Description
text Sets a short hint that describes the expected value of the URL field

Return Value

A String, representing a short hint that describes the expected value of the URL field

The following code shows how to change the placeholder text of a URL field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" placeholder="Address of web site">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/* w  ww.j  ava  2s .  com*/
    var x = document.getElementById("myURL").placeholder;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials