Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

remove foward slash.

Posted on 2014-04-02
6
130 Views
Last Modified: 2014-04-14
    var imgList = "";

                        $.each(listItems.imagename, function () {
                            imgList += '<img stack="true" src=images/' + (this.imagename) + '/>';
                        });
 $('.stack').append(imgList);

Open in new window


Incorporate this into the above ..
$('img').each(
    function(){
        var src = $(this).attr('src');
        if (src.indexOf('/') === 0){
            this.src = src.substring(1);
        }
    });

Open in new window


ending result

from this<img src="/folder1/folder2/image.jpg/" alt="" />
to this
<img src="/folder1/folder2/image.jpg" alt="" />

Open in new window

0
Comment
Question by:sevensnake77
  • 2
  • 2
  • 2
6 Comments
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 39974458
Why can't you just do this

var imgList = "";

$.each(listItems.imagename, function () {
    if (this.imagename.slice(-1) == '/') 
        this.imagename = this.imagename.substring(0, this.imagename.length -1);
    imgList += '<img stack="true" src=images/' + (this.imagename) + '/>';
});
$('.stack').append(imgList);
                                  

Open in new window

0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 250 total points
ID: 39974511
var imgList = "";

                        $.each(listItems.imagename, function () {

var imgsrc = (this.imagename.substr(-1,1)==="/") ? this.imagename.substr(0, this.imagename.length-1) : this.imagename;
                            imgList += '<img stack="true" src=images/' + (imgsrc) + '/>';
                        });
 $('.stack').append(imgList);

Open in new window

0
 
LVL 9

Author Comment

by:sevensnake77
ID: 39975056
Both problems did not remove the  forward slash from the src.
  var imgList = "";

                        $.each(listItems.myCirculars, function () {

                            var imgsrc = (this.FileName.substr(-1, 1) === "/") ? this.FileName.substr(0, this.FileName.length - 1) : this.FileName;
                            imgList += '<img stack="true" src=images' + '/' + (imgsrc)  + '/>';
                        });
                        $('.stack').append(imgList);

Open in new window

url was still
http://localhost:55302/images/image.jpg/

Open in new window

0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 55

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 39975451
They did in my test code.

<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
var image = "this is a test/";
alert(image);
if (image.slice(-1) == '/') image = image.substring(0, image.length - 1);
alert (image);
});

</script>
<style type="text/css">
</style>
</head>
<body>
</body>
</html>

Open in new window

0
 
LVL 43

Assisted Solution

by:Rob
Rob earned 250 total points
ID: 39976667
And this worked for me:  http://jsbin.com/tonab/1/edit?js,console,output

(code changed to implement your listitems)

var listItems = [
   {imagename: "myimage/1.jpg/"},
   {imagename: "myimage/2.jpg"}
];

var imgList = "";
$.each(listItems, function () {
    var imgsrc = (this.imagename.substr(-1,1)==="/") ? this.imagename.substr(0, this.imagename.length-1) : this.imagename;
    console.log(imgsrc);
    imgList += "<img stack='true' src=images/" + imgsrc + "/";
});
$(".stack").append(imgList);

Open in new window

0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 39999358
tks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question