Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: element content change Date: Wed, 06 Aug 2014 02:47:09 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: <87y4v2qtia.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx05.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="9861"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O929u2rfodPpPtmk17P+tyvYpgPV5/Ro=" Cancel-Lock: sha1:Eahx2q++4ntnmVTRxJ78N2zq940= sha1:OOelsGqQNiLdmpyVAvfxjKRE59I= X-BSB-Auth: 1.4feb239429b4e071f2e6.20140806024709BST.87y4v2qtia.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:25634 Andrew Poulos 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. >> >>
>> >> When the DOM loads, I want this to happen: >> >> City
>> >> 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 > > 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:
-- Ben.