I don't know what is getting wrong in my created function. I was trying to create a beautiful country selector. But it looks like this selector is gonna select nothing. Just joking, so my problem is according to my thinking my function should change the value of a input field classed as country_input on clicking multiple series of links. But it looks like it is not gonna work. But you guys can tell me how to achieve my goal.
-:::- HTML CODE -:::-
<input type="text" class="country_input" />
<br><br>
<a href="#country-select" id="Change-1" onclick="change_country();" >Country-1</a>
<a href="#country-select" id="Change-2" onclick="change_country();" >Country-2</a>
<a href="#country-select" id="Change-3" onclick="change_country();" >Country-3</a>
<a href="#country-select" id="Change-4" onclick="change_country();" >Country-4</a>
<a href="#country-select" id="Change-5" onclick="change_country();" >Country-5</a>
And so on....
-:::- jQuery CODE -:::-
jQuery.fn.change_country = function () {
var country_name = $(this).innerHTML;
$('input.country_input').val(country_name);
};
-:::- CSS CODE -:::-
body a { text-decoration: none; display: block; width: 50%; color: #555; background: rgb(240, 240, 240); border: 2px solid #000; border-style: none none solid none; font-family: calibri,segoe ui,arial, sans-serif; font-size: 12px; padding: 3px 5px; }
body a:hover { color: #000; background: #fff; }
body input { font-family: calibri,segoe ui,arial, sans-serif; font-size: 12px; padding: 3px 3px; width: 50%; outline: none; }
So can anyone help me out with this. As I'm a new comer in creating jQuery based functions so please help me out.
Am I doing wrong function defining? Am I missing something? Is my code is totally failure?
THANKS IN ADVANCE!