Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd flags to a country select dropdown
    primarykey
    data
    text
    <p>i am building a country selector using a pre-made list I found on google, and a smart method of pinpointing a flag on a png sprite posted on stackoverflow by roberkules (http://stackoverflow.com/questions/5409780/html-country-list-with-flags).</p> <p>I'm a beginner, and as much as I understand how each part works, I don't understand how I can "make" the jQuery read the ISO codes and then apply it to each country. I also added <code>&lt;i&gt;&lt;/i&gt;</code> to the first country to see if it would at least put the Spanish flag but nothing.</p> <p>! I am aware there is a similar question, but that one uses manual css coordinates, and i wanted it to work with the method in this JavaScript:</p> <pre><code>(function($) { // size = flag size + spacing var default_size = { w: 20, h: 15 }; function calcPos(letter, size) { return -(letter.toLowerCase().charCodeAt(0) - 97) * size; } $.fn.setFlagPosition = function(iso, size) { size || (size = default_size); return $(this).css('background-position', [calcPos(iso[1], size.w), 'px ', calcPos(iso[0], size.h), 'px'].join('')); }; })(jQuery); // USAGE: (function($) { $(function() { // on load: $('.country i').setFlagPosition('es'); }); })(jQuery);​ </code></pre> <p><a href="http://jsfiddle.net/3TvWs/" rel="nofollow">http://jsfiddle.net/3TvWs/</a> Is where I am now.</p> <p>Could anyone help, even just a hint?</p> <p>Edit: Sorry, i realize that i explained this badly. The (flag)Spain is just an example of how the pinpointing works. I actually meant the flags to be inside the dropdown, and not have that spain bubble at all. Sorry for the misunderstanding.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload