title: Getting value of custom attribute from selected option to a Javascript variable
body: <p>I have a country select with the option tag containing a custom attribute : name.</p>
  
  <p>I want to assign the value of this attribute to a javascript variable which would then be appended to a link and sent forward. </p>
  
  <p>But with the current code I am unable to set the value of the variable. </p>
  
  <p>Following is the line of code that I have currently:</p>
  
  
  
  <pre><code>var code = $("#countrySelect option:selected", this).attr("name");
  
  &lt;select name="CountrySelector" id="countrySelect"&gt;
      &lt;option selected="selected" value="0"&gt;Select&lt;/option&gt;
      &lt;option value="355" name="al"&gt;Albania&lt;/option&gt;
      &lt;option value="213" name="dz"&gt;Algeria&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I need to assign the value of the custom attribute "name" to the variable code.</p>
  
  <p>Can anyone please help me in resolving this?</p>