Solved

remove foward slash.

Posted on 2014-04-02
6
128 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 54

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 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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 54

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 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

770 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