Anexar (mostrar / ocultar texto) dinamicamente e quando mostram clicado / ocultar um conjunto de campos abaixo
Pergunta
Eu quero anexar (mostrar / ocultar texto) dinamicamente para um intervalo e quando clicou no texto particular, eu quero ter Show / Hide efeito em um conjunto de campos abaixo. I conseguido a tarefa de ter mostrar / esconder texto anexado ao span. Mas o problema surge quando eu clicar sobre o texto. Nada acontece, exceto o texto ao lado espaço fica alterado.
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 que mudanças eu preciso fazer. Agradecemos antecipadamente
Soluçã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');
$(".showHide").toggle('slow');
return false;
});
});
ou
$(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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow