• Resolved Guido

    (@guido07111975)


    Hi,

    I have a menu with class ‘nav-head’ and use this to create a select menu bar for mobile screens. Using this code for several years now.

    I don’t know much about jquery so I’m wondering if this code is still valid or already contains deprecated parts?

    jQuery(document).ready(function() {
    	// build <select> dropdown
    	jQuery("<select />").appendTo("div.nav-head");
    
    	// create option "Menu..."
    	jQuery("<option />", {
    		"selected": "selected",
    		"value": "",
    		"text": "Menu..."
    	}).appendTo(".nav-head select");
    
    	// populate
    	jQuery(".nav-head ul li a").each(function() {
    		var el = jQuery(this);
    
    		if(el.parents('.nav-head ul ul').length) {
    			// if there are ul in li
    			jQuery('<option />', {
    				'value': el.attr('href'),
    				'text':  '- ' + el.text()
    			}).appendTo('.nav-head select');
    		} else {
    			// if no ul in li
    			jQuery('<option />', {
    				'value': el.attr('href'),
    				'text': el.text()
    			}).appendTo('.nav-head select');
    		}
    	});
    
    	// make links work
    	jQuery(".nav-head select").change(function() {
    		window.location = jQuery(this).find("option:selected").val();
    	});
    });

    Thanks in advance.

    Guido

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Hey Guido,

    I don’t know much about jQuery either, but your browser console (usually under developer tools or something similar) should warn you if your page is using deprecated (or soon to be deprecated) code. Look at the JS tab. Clear what’s there, then reload your page to ensure any warnings apply to your page.

    BC

    Thread Starter Guido

    (@guido07111975)

    Hi,

    Thanks, I will check this out.

    I can also check each element of my code on the official jquery site..

    Guido

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Select navigation > is my code still valid?’ is closed to new replies.