Welcome to WebmasterWorld Guest from 50.19.190.144

Forum Moderators: open

Message Too Old, No Replies

Attribute Default Value

     
7:00 am on Jul 23, 2014 (gmt 0)

Junior Member

5+ Year Member Top Contributors Of The Month

joined:Mar 1, 2010
posts: 194
votes: 0


Can you get an attribute default value so you don't have to repeat it in the following example:

<p title="foo" id="p">Hello, world!</p>
<input type="text" id="i">
<script>
var p = document.getElementById('p'),
i = document.getElementById('i');
i.oninput = function () {
p.title = this.value;
if (this.value == 'bar') {
p.title = 'foo';
}
};
</script>

DEMO [jsfiddle.net]

Is there something like
p.title = p.title.defaultValue
as we use for text fields?
1:10 pm on July 23, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
posts: 4965
votes: 10


No, but you could store the attribute's default value in a data attribute.

<p title="foo" id="p" data-title="foo">Hello, world!</p>
<input type="text" id="i">
<script>
var p = document.getElementById('p'),
i = document.getElementById('i');
i.oninput = function () {
p.title = this.value;
if (this.value == 'bar') {
p.title = p.getAttribute('data-title');
}
};
</script>
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members