0

I want to have a link to add to each of the elements in the array below:

var breadcrumb = ['About','Test2','Test3','Test4' ];

I tried to add

<a href ="/about/">About</a> 

etc and so on but not good.

Is there a way of doing this within the array? And how can I print them to my aspx page?

Thank you

6
  • When you assign it as an element it's just a string. I'm guessing you didn't wrap it in quotes. var breadcrumb = ["<a href =\"/about/\">About</a>"] Commented Nov 22, 2016 at 1:49
  • Oh, I did not, no. Thanks. Commented Nov 22, 2016 at 1:52
  • What do you want to store in the array? Is it the element tag with link? or the Strign of link only? Commented Nov 22, 2016 at 1:52
  • @msagala I wish to make a link above the page title which acts as the link and text "about" for the content 'on' page. Which is about. If that makes sense :-) Commented Nov 22, 2016 at 1:54
  • Use createElement to make a link, set the address, then add it to the array. Commented Nov 22, 2016 at 1:56

1 Answer 1

2

Yes, you can put links or anything into a javascript array (use the real href values for you):

var breadcrumb = [
    "<a href='about.html'>About</a>",
    "<a href='test2.html'>Test2</a>",
    "<a href='test3.html'>Test3</a>",
    "<a href='test4.html'>Test4</a>"
];

If by printing you mean writing them to the page - I don't think this has anything specific to do with aspx since the array is in Javascript. You could do this:

for( var index = 0; index < breadcrumb.lengh; index++ ){
     document.write("<div>" + breadcrumb[index] + "</div>" );
}

Or you could use jQuery for more elaborate DOM manipulation to add your links to the page.

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.