Skip to content Skip to sidebar Skip to footer

How To Remove Attributes From HTML Using Javascript?

I have an HTML with say a textfield (input element). This simply displays a text field on my page with a default v

Solution 1:

...I don't want to see this default value.

Just set the value property directly to an empty string.

document.getElementsByName('capacity')[0].value = '';

jsFiddle.


Solution 2:

Give your text field and id like <input name="capacity" type="text" id="text" value="blah blah blah"> document.getElementById['text'].value = "";


Solution 3:

This is your html tag. You will need to add a ID to it

<input id="capacity" name="capacity" type="text" value="blah blah blah">

This is just to fire the javascript function

<input type="submit" value="Click" onclick="javascript:return reset();" />

The following function will reset the value of the selected element

<script type="text/javascript" language="javascript">
    function reset() {
        document.getElementById("capacity").value = "";
        return false; // In order to avoid postback
    }   
</script>

If you are not using form and you want to use it with just the name you can try the following

 this.capacity.value = '';

Post a Comment for "How To Remove Attributes From HTML Using Javascript?"