Reputation: 304
Is there a html tag to simply give a text an id/class?
Let's say I have the text "email" in front of an input
tag, and i want to change the text (with js) on button click. I'd need an id... p
would kick the input on a new line (which i don't want) and font
is a bit outdated.
Any ideas?
Upvotes: 2
Views: 9678
Reputation: 67748
The element for describing a subsequent input
tag should be a label
tag, which has to have a for
attribute that contains the name of the corresponding input
tag. You can therefore select that element as a label with a particular attribute.
Example
<label for="email">Email: </label><input type="text" name="email" />
and to select it and change its text:
jQuery('label[for=email]').text('your new label text');
Note that this is the only solution (for labeling inputs) which also meets accessibility standards.
You can style it any way you want using CSS.
Upvotes: 4
Reputation: 943163
The <span>
element is a generic (i.e. it has no associated semantics) inline element that can be used for marking some content for access via CSS / JS / etc.
However, "the text 'email' in front of an input" sounds very much like a <label>
element so you should probably use that instead.
Upvotes: 4
Reputation: 7336
<span id="..." class="..."></span>
is the element you are looking for, it stays completly inline and doesn't move any content, but still is accessible through JavaScript.
Upvotes: 3