Search code examples
jqueryasmselect

Set asmselect id while initiating


Is there any way to set id for asm select instead of having it initiated automatically? Thank you in advanced.

<select multiple id="mySelect">
   <option value="volvo">Volvo</option>
   <option value="saab">Saab</option>
   <option value="opel">Opel</option>
   <option value="audi">Audi</option>
</select>

$("#mySelect").asmSelect({
    animate: true,
    addItemTarget: 'bottom'
});

I don't want the asmSelect id to be "asmSelect0", please show me how to change it. Thank you.


Solution

  • It looks like this plugin renders an entirely new visual representation of your original select element and then hides it. The id for the new select container is a composition of options.selectClass + index. The selectClass is hard coded into the plugin and index is determined internally. The author left no exposed method to change these variables.

    If you want this id to be different you'll need to change the options object in the plugin code itself or change the element's id with JavaScript after you call the plugin.

    To change the ID afterwards just use the JQuery .attr method

    $('#asmSelect0').attr('id', 'newId'); 
    

    Replace newId with the id you choose.