Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25634
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: element content change |
| Date | 2014-08-06 02:47 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87y4v2qtia.fsf@bsb.me.uk> (permalink) |
| References | <ba13e4c4-70c8-4e8d-9a39-9c3bfecf4f6f@googlegroups.com> <xuWdnZJt5KHAGXzOnZ2dnUVZ_iydnZ2d@westnet.com.au> |
Andrew Poulos <ap_prog@hotmail.com> writes:
> On 6/08/2014 10:05 AM, teddybubu@gmail.com wrote:
>> Hello,
>> I can't ask this in the jquery forum so I came here.
Why not?
>> Sorry for the mixup.
>> I want to add content to an html input using javascript/jquery but I
>> can not seem to make it work.
>>
>> <input type="text" id="city"/> <br/>
>>
>> When the DOM loads, I want this to happen:
>>
>> <input type="text" id="city"/> City<br/>
>>
>> Basically the City will be next to the input box as a label.
>> Why won't this work?
>> $('#city').change('City');
>> or
>> $('#city').val('City');
>
> If
> <input type="text" id="city" value="">
> then (once the input is ready)
> document.getElementById("city").value = "City";
It seems the OP wants the text next to the input element.
To the OP: this may do what you want:
var t = document.getElementById('city');
t.parentNode.insertBefore(document.createTextNode('City'),
t.nextSibling);
but you should consider another approach. It's often better to have an
element in the document that you simply fill in. You can then move it
about as you work on the layout, style it like any other part of the
document, etc. What's more, HTML even defines an element whose role is
to be a label for a form element: label:
<input type=text id=city><label for=city id=citylabel></label><br>
--
Ben.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
element content change teddybubu@gmail.com - 2014-08-05 17:05 -0700
Re: element content change Andrew Poulos <ap_prog@hotmail.com> - 2014-08-06 11:23 +1000
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-06 02:47 +0100
Re: element content change "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-08-06 06:47 +0300
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-06 20:27 +0100
Re: element content change "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-06 15:16 +0200
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-06 20:37 +0100
Re: element content change "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-08-06 23:19 +0300
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-06 21:54 +0100
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-06 21:59 +0100
Re: element content change "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-07 00:59 +0200
Re: element content change "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-08-07 08:28 +0300
Re: element content change Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-08-07 11:42 +0100
Re: element content change "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-08 18:48 +0200
Re: element content change "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-07 00:54 +0200
Re: element content change teddybubu@gmail.com - 2014-08-05 19:36 -0700
Re: element content change Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-08-06 08:52 +0200
Re: element content change Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-06 12:52 +0000
Re: element content change teddybubu@gmail.com - 2014-08-06 05:58 -0700
csiph-web