Solved

div tag has inner html - I want to replace **just** the text that is inside, not the other stuff

Posted on 2011-09-19
3
301 Views
Last Modified: 2012-05-12
My current attempt:

$('div.shippingfieldformatting:contains("Address2")');  




<div id="ctl00_ContentPlaceHolder1_ShippingInfo1_Div3" class="shippingfieldformatting">Address2:<input name="ctl00$ContentPlaceHolder1$ShippingInfo1$tbShipAddress2" type="text" id="ctl00_ContentPlaceHolder1_ShippingInfo1_tbShipAddress2" style="width:255px;" /></div>

Essentially I want to replace the inner html text of "Address2:" with "Address2:&nbsp;&nbsp;" but I want to leave the <input> tag as it is ---- I just want to replace the text portion of the inner html.
0
Comment
Question by:knowlton
3 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 100 total points
Comment Utility
var input = $("div.shippingfieldformatting input");

 $("div.shippingfieldformatting").html("Address2:&nbsp;&nbsp;").append(input);
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
Comment Utility
var word = "Address2:";
var $div = $('div.shippingfieldformatting:contains("' + word + '")');
var oldHTML = $div.html();
var newHTML = oldHTML.replace(word,word+"&nbsp;&nbsp;");
$div.html(newHTML);

Open in new window


test page : http://jsfiddle.net/YdcuW/
0
 
LVL 5

Author Closing Comment

by:knowlton
Comment Utility
thx
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now