简体   繁体   中英

How should i show select title with css

Hello Guys Please Help me for this I didn't how I show select title. I want to show above When should we call you?.

please check my code Thanks:-

 <select name="myfirst" title="When should we call you?">
    <option class="optnoval"></option>
    <option value="today" id="df">today</option>
    <option value="tommorow" id="df">tommorow</option>
    <option value="sunday" id="dfd">sunday</option>
 </select>

Please check online codepen code link:- https://codepen.io/anon/pen/EQBbyG

You can add a <label> in your HTML Markup.

 <label for="myfirst">When should we call you?</label> <select name="myfirst" id="myfirst" title="When should we call you?"> <option class="optnoval"></option> <option value="today" id="df">today</option> <option value="tommorow" id="df">tommorow</option> <option value="sunday" id="dfd">sunday</option> </select>

If you use jQuery you can select all the <select> elements with a title attribute, and copy its value into the first <option> .

 $("select[title] option:first-child").text(function(i, oldtext) { if (oldtext.trim() == '') { return $(this).parent().attr("title"); } });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="myfirst" title="When should we call you?"> <option class="optnoval"></option> <option value="today">today</option> <option value="tommorow">tommorow</option> <option value="sunday" >sunday</option> </select> <select name="mytime" title="What time of day?"> <option class="optnoval"></option> <option value="morning">Morning</option> <option value="afternoon" >Afternoon</option> <option value="evening">Evening</option> </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM