Solved

remove foward slash.

Posted on 2014-04-02
6
122 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 51

Accepted Solution

by:
Julian Hansen earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 51

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
tks
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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 …
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now