Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
341 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:Tom Knowlton
3 Comments
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 400 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 1600 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:Tom Knowlton
ID: 36563081
thx
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

972 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