It should only open a new window with a _blank target on the link. Have you dropped a console.log into the if statement to see if it's trying to open in a new window? – czarchaicDec 14 '09 at 5:12
2Use change(), but on the select element, not the option: select.change(function() { window.location = $(this).find("option:selected").val(); }); <-----this should get the above code to work in Chrome. – The Pied PipesJul 12 '14 at 21:24
As with any jQuery code you want to run on page load, you have to wrap it inside $(document).ready(function() { ... }); block, or inside it's shorter version $(function() { ... });. I updated the function to show this.
You are trying to execute the script inside <style> tags, change those to <script>. I also updated my function, there was a small mistake. – Tatu UlmanenDec 13 '09 at 18:20
oh , my mistake , solved now now i added ur latest code it's working now jsbin.com/igano but on select a item from dropdown i wanted to open link in new window – Jitendra VyasDec 13 '09 at 18:27
@Jitendra, opening link on change and styling the select is out of the scope for this question, Google has a lot of resources for both of those. If the code is working, lets just close this one. – Tatu UlmanenDec 13 '09 at 18:38
Yes code is working and great thanks for it. I closed the question but if u can give the way to open links in new window then it would be better – Jitendra VyasDec 13 '09 at 18:42
Thank you all for posting the codes. My scenario is similar but my situation is for Responsiveness that for x-size it would switch to a dropdown list, then if not x-size, using csswatch to check for the "display" properties of an element that has certain amount of width set to it (eg: 740px). Thought I share this solution for anyone who is interested. This is what I have combined with Tatu' codes. Instead of replacing the html, I created then hide the new html then only add them when necessary:
I have recently created a solution where the ul transformed, mimics nearly completely the select.
It has in adition a search for the options of the select and supports the active state. Just add a class with name active and that option will be selected.
Where #id is an id for the unordered list and 767 is the minimum width of the window for the convertion to take place. This is very useful if you want the convertion to take place only for mobile or tablet.shareimprove this answer follow edited Apr 1 '17 at 15:20answered Apr 1 '17 at 15:02quAnton60666 silver badges99 bronze badgesadd a comment