Reputation: 131
I have the following html code , and I want to search the Welcome and make it bold .
<div class="welcome-msg">Welcome, First Name | </div>
the Output should be like this using DOM manipulation.
<div class="welcome-msg"><strong>Welcome</strong>, First Name | </div>
thanks ..
Upvotes: 1
Views: 94
Reputation: 1104
You could load the text as a variable but doing
var myvar=$('.welcome-msg').html();
to change the text
myvar=myvar.replace('Welcome', '<strong>Welcome</strong>');
then to put it back
$('.welcome-msg').html(myvar);
or in a single line
$('.welcome-msg').html($('.welcome-msg').html().replace('Welcome', '<strong>Welcome</strong>'));
Tested and work fine
Upvotes: 0
Reputation: 382656
You need simple replace
there:
var txt = $('div.welcome-msg').text();
$('div.welcome-msg').text(txt.replace('Welcome', '<strong>Welcome</strong>'));
Upvotes: 0
Reputation: 56430
var $welcomeMsg = $('.welcome.msg');
$welcomeMsg.html($welcomeMsg.text().replace(/(welcome)/i, '<strong>$1</strong>'));
Upvotes: 1