AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



html-jquery: How to remove value attribute from all options tag?

I have a dropdown having some options with its value. Now i want to have same dropdown in another div but i want to pass this time option label in value not the different value like below.
<div id="language-code">
<select id="first" name="languagecode">
<option value="">Select</option>
<option value="En">English</option>
<option value="Hi">Hindi</option>
<option value="Kr">Korean</option>
<option value="Ur">Urdu</option>
<option value="Fr">French</option>
</select>
</div>
<div id="language">

</div>

Now in last div tag having id="language" i want to inject the following html code:
<select id="first" name="language">
<option>Select</option>
<option>English</option>
<option>Hindi</option>
<option>Korean</option>
<option>Urdu</option>
<option>French</option>
</select>

html x 24
jquery x 12
Posted On : 2015-11-17 22:54:04.0
profile Rishi Kumar - anyforum.in Rishi Kumar
523188245674
up-rate
5
down-rate

Answers


To copy the first dropdown call html() on outer div of first dropdown and again call html(´´). and having same id for both dropdown is not a good approach. so after injecting the html content change the id of second dropdown and call removeAttr(´attr´) on second dropdown children() which will refer the option tag of second dropdown. See below code:

RemoveAttr.html:
------------------------------------------------
<html>
<head><title>Removing All options value attribute form a dropdown</title></head>
<body>
<div id="language-code">
<select id="first" name="languagecode">
<option value="">Select</option>
<option value="En">English</option>
<option value="Hi">Hindi</option>
<option value="Kr">Korean</option>
<option value="Ur">Urdu</option>
<option value="Fr">French</option>
</select>
</div>
<div id="language">

</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(´#language´).html($(´#language-code´).html());
$(´#language #first´).attr(´id´,´second´);
$(´#second´).attr(´name´,´language´);
$(´#second´).children().removeAttr(´value´);
});
</script>
</body>
</html>

Posted On : 2015-11-17 23:39:11
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129554552
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in