jquery - Make CSS menu item load website instead of changing placeholder with javascript -


i have css menu, when try , load url menu, google in example. changes name of placeholder , doesn't load page. idea how change this?

thanks help!

fiddle example, try load google in menu : http://jsfiddle.net/n877s/3/

            function dropdown(el) {             this.dd = el;             this.placeholder = this.dd.children('span');             this.opts = this.dd.find('ul.dropdown > li');             this.val = '';             this.index = -1;             this.initevents();         }         dropdown.prototype = {             initevents : function() {                 var obj = this;                  obj.dd.on('click', function(event){                     $(this).toggleclass('active');                     return false;                 });                  obj.opts.on('click',function(){                     var opt = $(this);                     obj.val = opt.text();                     obj.index = opt.index();                     obj.placeholder.text(obj.val);                 });             },             getvalue : function() {                 return this.val;             },             getindex : function() {                 return this.index;             }         }          $(function() {              var dd = new dropdown( $('#dd') );              $(document).click(function() {                 // dropdowns                 $('.wrapper-dropdown-3').removeclass('active');             });          }); 

html

<div class="wrapper-demo"> <div id="dd" class="wrapper-dropdown-3" tabindex="1">     <span>transport</span>         <ul class="dropdown">         <li><a href="#">classic mail</a></li>         <li><a href="#">ups delivery</a></li>         <li><a href="http://www.google.com">google</a></li>         </ul> </div> 

you preventing standard behavior of links (even descendent links) right here:

        obj.dd.on('click', function(event){             $(this).toggleclass('active');             return false;         }); 

add following code prevent clicks on menu items bubbling above handler:

        obj.dd.find('a').on('click',function(event){             event.stoppropagation();         }); 

here's working fiddle.

note: check console see result, jsfiddle won't load google.com in iframe (sameorigin policy).


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -