www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript replacing

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Javascript replacing

    Hello, i want to replace 'download' to 'download_prev'
    ex:

    <a href=''><img src='/download-0-756a8f457f516a948b89/00990Nature.jpg'/></a><br/>

    i want to make:

    <a href=''><img src='/download_prev-0-756a8f457f516a948b89/00990Nature.jpg'/></a><br/>

    please only simple js if you can bcoz i will use for opera mini users and no php

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    Code:
    var images = document.getElementsByTagName('img');
    var pattern = /^\/download/;
    var replacement = '/download_prev';
    for (var i = 0, len = images.length; i < len; i++) {
    	images[i].src = images[i].getAttribute('src').replace(pattern, replacement);
    }
    I hope it's simple enough.

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