Adjuntar (mostrar / ocultar texto) de forma dinámica cuando se hace clic y mostrar / ocultar un conjunto de campos de abajo
Pregunta
Quiero adjuntar (texto mostrar / ocultar) dinámicamente a un tramo y cuando se hace clic en ese texto en particular, quiero tener efecto mostrar / ocultar en un conjunto de campos a continuación. Me acheived la tarea de tener mostrar / ocultar texto anexado a abarcar. Pero el problema surge cuando hago clic en ese texto. No pasa nada, excepto el texto al lado lapso se cambia.
HTML:
<span>Store Dropdown</span>
<fieldset id="fieldset-store" class="showHide">
<legend>Choose by item:</legend>
<label for="prodtype">Type:</label>
<select name="prodtype" id="prodtype">
<option value="0" selected="selected">Choose type</option>
<option value="1"> Sample1</option>
<option value="2"> Sample2</option>
<option value="3"> Sample3</option>
<option value="4"> Sample4</option>
</select>
<label for="brandtype">of:</label>
<select name="brandtype" id="brandtype">
<option value="0" selected="selected">Choose brand</option>
<option value="1"> Brand1</option>
<option value="2"> Brand2</option>
<option value="3"> Brand3</option>
<option value="4"> Brand4</option>
</select>
<label for="prodprice">Price:</label> <input id="prodprice" name="prodprice" value="" type="text">
</fieldset>
Código JS:
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(this).next().toggle('slow');
return false;
});
});
Pls me sugerir qué cambios tengo que hacer. Gracias de antemano
Solución
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(".showHide").toggle('slow');
return false;
});
});
o
$(document).ready(function(){
$(".showHide").prev().append(' <a href="#" class="showHideLink">Show</a>');
$(".showHide").hide();
$('a.showHideLink').click(function() {
if ($(this).html()=='Show')
$(this).html('Hide');
else
$(this).html('Show');
$(this).parent().next().toggle('slow');
return false;
});
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow