Take the 2-minute tour ×

i am trying to change placeholders for values in a form if internet explorer is version 9 or 8, i got this pice of code.

if( $("html").data("version") == "IE9-10"  ){
        var brand = $(".brand input");
        var value = brand.attr("placeholder");
        var model = $(".model input");
        var value2 = model.attr("placeholder"); 

I will like to know if there is a way i can make code more simple and less repetitive to achieve this same effect, i just need to select .brand input and .model input, store it placeholder value and replace the in put value with the placeholder value, I will appreciate if you guys could help me with this.

here is the HTML, im using a plugin who convert select to custom design, but the plugin uses placeholder and I need to support ie9 and ie8, so ill show you the html of the select and the html output of the plugin.

<select name="brand" class="brand" style="display: none;">
    <option value="">Marca</option>

Plugin Output

<div class="brand">
    <input type="text" value="" placeholder="Marca">
        <li data-value="volvo" class="">Volvo</li>
        <li data-value="saab" class="">Saab</li>
        <li data-value="mercedes" class="">Mercedes</li>
        <li data-value="audi" class="">Audi</li>
        <li class="minict_empty">Ningun resultado concuerda con la palabra.</li>
share|improve this question
You only show the div.brand markup, but you said the .model case had failed. Can you please include ALL of your HTML? –  Platinum Azure Sep 26 '13 at 20:26
add comment

3 Answers

up vote 2 down vote accepted


$('.brand, .model').find('input').val(function(){
   return this.placeholder;
   // or $(this).attr('placeholder'); if IE cannot access the attribute directly

demo at http://jsfiddle.net/deE5A/

share|improve this answer
I didn't realize .val() accepted functions! I actually like this better than my answer. (Note for OP: You need jQuery 1.4+) –  Platinum Azure Sep 25 '13 at 22:24
@PlatinumAzure it has been added since v1.4 (api.jquery.com/val/#val-functionindex--value). Most (if not all) setter functions support this syntax –  Gaby aka G. Petrioli Sep 25 '13 at 22:28
This one worked really good for me @GabyakaG.Petrioli , but i still wana know why .each() doesn't worked, it was my primary option. –  Jhonnatan Gonzalez Rodriguez Sep 25 '13 at 22:43
@JhonnatanGonzalezRodriguez, you haven't posted the code that didn't work, so i cannot really comment on why it failed.. if you add it to your question i can take a look.. –  Gaby aka G. Petrioli Sep 25 '13 at 22:48
@GabyakaG.Petrioli hahahah sorry, this is the code $(".brand input, .model input").each(function(){ $(this).val($(this).attr("placeholder")); }); –  Jhonnatan Gonzalez Rodriguez Sep 25 '13 at 23:03
add comment

Since you're doing the same operation on each one, you could combine the selectors and use .each():

        // In this function, "this" is the raw DOM element being iterated over,
        // so $(this) is a jQuery wrapper around that element.

        var $this = $(this);   // I like caching to save jQuery constructor calls :-)
share|improve this answer
i already used this one, butt seems not to work on ie9, it only replaces .brand input the other one remains white :( couldnt understand why –  Jhonnatan Gonzalez Rodriguez Sep 25 '13 at 22:25
Can you please show us your HTML (edit your question)? Maybe there's something odd in the HTML that we're not taking into account. –  Platinum Azure Sep 25 '13 at 22:27
I editted the post soy know you can see my HTML –  Jhonnatan Gonzalez Rodriguez Sep 25 '13 at 22:33
add comment

That should do it :).

share|improve this answer
add comment

Your Answer


