jquery - javascript getElementById start with -
i want select div
start *
change display: block
display:hidden
function select_to_text(a) { var = '#' + a; var aa = $(as).val(); if (aa == "0") {} else { //var $eles = $(":*[name^='personal_family_type_']").css("background-color","yellow"); document.getelementbyid(a + "_" + aa + "_block").style.display = 'block'; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group"> <label for="personal_family_type" class="control-label col-sm-2">type</label> <div class="col-sm-10"> <select size="1" id="personal_family_type" name="personal_family_type" class="form-control btn btn-primary" onchange="select_to_text('personal_family_type')"> <option value="0">----</option> <option value="wife">wife</option> <option value="husband">husband</option> <option value="son">son</option> <option value="all">show all</option> </select> <div id="personal_family_type_wife_block" style="display :none"> wife </div> <div id="personal_family_type_husband_block" style="display :none"> husband </div> <div id="personal_family_type_son_block" style="display :none"> son </div> </div> </div>
here solution done in jquery. remove onclick html element.
$( document ).ready(function() { $('#personal_family_type').on('click', function() { $("#"+this.id + "_" + this.value + "_block").toggle(); }); });
here demo
Comments
Post a Comment