Is there a way to onload, append a span tag to to the end of all input fields that are equal to type text.
ex: <input type="text"><span></span>
All text inputs will have that span tag added to the end of it on page load.
Append a SPAN to all input type="text" fields
Moderator: General Moderators
Re: Append a SPAN to all input type="text" fields
It's really easy with a JavaScript framework like jQuery:
code not tested 
It's possible with pure javascript of course, you can get all input elements via document.getElementsByTagName() and then in a loop check their type and append the span element.
Code: Select all
$(document).ready(function(){
$('input[type="text"]').each(function(){
$(this).append('<span> ...</span>');
});
});
It's possible with pure javascript of course, you can get all input elements via document.getElementsByTagName() and then in a loop check their type and append the span element.
Re: Append a SPAN to all input type="text" fields
I do run jQuery and love it. However that does not work with it?
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: Append a SPAN to all input type="text" fields
he said he didn't test the code. it may need adjustments
Re: Append a SPAN to all input type="text" fields
Well, the code above produces invalid HTML - <input type="text"><span/></input>icesolid wrote:I do run jQuery and love it. However that does not work with it?
The correct code, and this time it's tested, is:
Code: Select all
$(document).ready(function(){
$('input[type="text"]').each(function(){
$(this).after('<span> ...</span>');
});
});