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
305 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
ID: 36561659
var input = $("div.shippingfieldformatting input");

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

Accepted Solution

by:
leakim971 earned 400 total points
ID: 36561680
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
ID: 36563081
thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
update field on focusout 15 43
DataTables - 2 tables one renders and one does not. 17 31
jquery add something to a div 4 37
Full Screen problem when auto scale IFRAME 2 55
DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

948 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

21 Experts available now in Live!

Get 1:1 Help Now