0

I am having a hard time making out what this would read:

<img src="/path/frontend/bigpath/default/images/heyhey/coolguy/' + partElements['awesometimes']['color'] + '.png">

What would be the URL output of this image?


It is in relation to this page; Bicycle Customizer.

I love this website and am trying to better understand how they accomplished this in JS.

http://www.myownbike.de/

4
  • 1
    Given just that line, the URL would literally be "/path/frontend/bigpath/default/images/heyhey/coolguy/' + partElements['awesometimes']['color'] + '.png". Please provide more context. Commented Oct 15, 2013 at 3:50
  • 3
    It would result in a syntax error. " cannot end with a ' Commented Oct 15, 2013 at 3:50
  • 1
    @karthikr: If you interpret this as JavaScript (which it seems you do), then the syntax error would already be at <img. The quotation marks wouldn't cause a syntax error at all. As you can see at the end, there is a closing ", so the ' are inside of the double quoted string. In JS, "foo'bar'" is a valid string. Commented Oct 15, 2013 at 3:52
  • what do you get when you put console.log(partElements['awesometimes']['color'])?. that will be your image name. Provide some more code to answer your query. Commented Oct 15, 2013 at 3:57

1 Answer 1

3

Your question is unclear. As the value that it gets evaluated is purely dependent on

partElements['awesometimes']['color'] ( I assume partElements is JavaScript array )

Also, it would result in syntax error as the concatenation done is incorrect. Moreover, the concatenation should be done part of JavaScript. Your HTML code cannot do it. If you are trying to do it in HTML, it will never work.

Below code might help you out.

<script type="text/JavaScript">
window.onload=function(){
    document.getElementById('myImg').src = "james" + "bond" + ".jpg";
}
</script>
<img src="" id="myImg">

Let the JavaScript do its concatenating business. Let HTML do its rendering business.

If you are finding tough time in what that gets evaluated to, start using debugging tools. All the major browsers provide these features.

Chrome debugging tools are good. References : https://developers.google.com/chrome-developer-tools/docs/javascript-debugging

Try evaluating the string concatenation of img src in chrome console to get to know it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.