/    Sign up×
Community /Pin to ProfileBookmark

How To replace a part of sring in jQuery

Hi
I have one problem,i have one string that contains image ang sring .but i want to replace only string.
how can i do this in jQuery

Thank you so much in advance

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Ay__351_eApr 15.2012 — I don't use Jquery.
<br/>
&lt;script type="text/javascript"&gt;
// http://www.w3schools.com/jsref/jsref_obj_string.asp
// http://www.w3schools.com/jsref/jsref_obj_regexp.asp

var str = '&lt;img src="" alt=""&gt; text text text';

var re=/&lt;[^&gt;]+&gt;/;

alert(re.test(str)); // true

alert(str.match(re)); // &lt;img src="" alt=""&gt;

var s = ' metin metin metin';

var yeni = str.match(re) + s;

alert(yeni); // &lt;img src="" alt=""&gt; metin metin metin

// or

alert(str.indexOf('&gt;') ); //18

var t = str.slice(str.indexOf('&gt;') +1 );

alert(t); // text text text

var T = ' Burada &amp;#351;imdi ba&amp;#351;ka bir yaz&amp;#305; var.';

yeni2 = str.replace(str.slice(str.indexOf('&gt;') +1 ), T);

alert(yeni2); // &lt;img src="" alt=""&gt; Burada &amp;#351;imdi ba&amp;#351;ka bir yaz&amp;#305; var.

&lt;/script&gt;
×

Success!

Help @aneesh29 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...