Results 1 to 2 of 2

Thread: How To replace a part of sring in jQuery

Hybrid View

  1. #1
    Join Date
    Mar 2012

    Smile How To replace a part of sring in jQuery

    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

  2. #2
    Join Date
    Sep 2007
    I don't use Jquery.
    <script type="text/javascript">
    // http://www.w3schools.com/jsref/jsref_obj_string.asp
    // http://www.w3schools.com/jsref/jsref_obj_regexp.asp
    var str = '<img src="" alt=""> text text text';
    var re=/<[^>]+>/;
    alert(re.test(str)); // true
    alert(str.match(re)); // <img src="" alt="">
    var s = ' metin metin metin';
    var yeni = str.match(re) + s;
    alert(yeni); // <img src="" alt=""> metin metin metin
    // or
    alert(str.indexOf('>') ); //18
    var t = str.slice(str.indexOf('>') +1 );
    alert(t);  // text text text
    var T = ' Burada şimdi başka bir yazı var.';
    yeni2 = str.replace(str.slice(str.indexOf('>') +1 ), T);
    alert(yeni2);  // <img src="" alt=""> Burada şimdi başka bir yazı var.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles