Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

remove foward slash.

Posted on 2014-04-02
6
Medium Priority
?
141 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:Seven price
  • 2
  • 2
  • 2
6 Comments
 
LVL 60

Accepted Solution

by:
Julian Hansen earned 1000 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 1000 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:Seven price
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 60

Assisted Solution

by:Julian Hansen
Julian Hansen earned 1000 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 1000 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:Seven price
ID: 39999358
tks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

916 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