Search code examples
javascriptjqueryjavascript-objects

Can somebody help me understand this more. Javascript selection


How does this work? and what are other ways to do it?

redirect = function(sectionName){

  document.location.assign('about/' + sectionName + '/');    
};

Solution

  • If by block menu you mean an HTML menu made of other HTML elements like divs, ordered / unordered lists then the response below applies, other than that, please explain in detail what do you mean by block menu

    select is an object which contains a reference to the HTML "select" tag, so is options in the line var opsArray= select.options; the code provided by you will not work with block menus.

    You have will have to create a function which looks totally different.

    Let's say this is your menu:

    <ul id="list">
     <li id="about" onclick="redirect(this.id)">About</li>
     <li id="news" onclick="redirect(this.id)">News</li>
    </ul>
    

    your javascript code will have to be:

    redirect = function(sectionName){
      document.location.assign('projects/' + sectionName + '/');    
    };
    

    This is one way to do it, there are too many ways to do this. Hopefully I understood your question correctly.