Solved

remove foward slash.

Posted on 2014-04-02
6
137 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
[X]
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
  • 2
  • 2
  • 2
6 Comments
 
LVL 58

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: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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 58

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:Seven price
ID: 39999358
tks
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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)
Suggested Courses

631 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