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
314 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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

839 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