jquery change div text

'<div>\n\ <div>'+ '<span></span>' + dialog_title+'</div></div>

I have a div constructed using the above string. After some processing..I have to change the dialog_title in the above div. I am trying to do it with the following code

$('#'+div_id+' .widget-head').text("new dialog title");

While this changes the dialog title..it removes the span element which is used to open a dialog box.

I tried to the replaceWith method with a string with new dialog title..but that shows NaN for title and the span though visible cant be clicked(are events disabled?)

How do I change the text without losing the span and ability to click it.

Thanks in advance.

3 Answers

Put the title in its own span.

<span>'+dialog_title+'</span>
$('#dialog_title_span').text("new dialog title");
1

I think this will do:

$('#'+div_id+' .widget-head > span').text("new dialog title");
2

best and simple way is to put title inside a span and replace then.

'<div>\n\ <div>'+ '<span></span>' + '<span>'+ dialog_title+ '</span>' '</div></div>

now you can simply use this:

$('#'+div_id+' .widget-head sp#spTitle').text("new dialog title");
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like