2
I got the following Snippet
, where by clicking on the content of the div is shown (revealed) and when clicking on the content of the div is collected (hidden), however the images are not changing correctly, someone knows how to fix it!?
// Script para revelar/esconder os endereços
jQuery.fn.toggleText = function(a, b) {
return this.html(this.html().replace(new RegExp('(' + a + '|' + b + ')'), function(x) {
return (x == a) ? b : a;
}));
}
$(document).ready(function() {
var img = document.getElementById('mostraEsconde');
$('.tgl').css('display', 'none')
$('legend', '#box-toggle').click(function(){
$(this).next().slideToggle('slow')
.siblings('.tgl:visible').slideToggle('fast');
// aqui começa o funcionamento do plugin
$(this).toggleText(img.srcset = 'https://cdn2.iconfinder.com/data/icons/icojoy/noshadow/transparent/png/24x24/001_01.png', img.srcset = 'https://cdn2.iconfinder.com/data/icons/icojoy/shadow/standart/png/24x24/001_02.png')
.siblings('legend').next('.tgl:visible').prev()
.toggleText(img.srcset = 'https://cdn2.iconfinder.com/data/icons/icojoy/noshadow/transparent/png/24x24/001_01.png', img.srcset = 'https://cdn2.iconfinder.com/data/icons/icojoy/shadow/standart/png/24x24/001_02.png')
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<div id="box-toggle">
<fieldset>
<legend style="overflow: hidden;">
Endereço Cobrança
<img src="https://cdn2.iconfinder.com/data/icons/icojoy/noshadow/transparent/png/24x24/001_01.png" id="mostraEsconde" alt="Mostrar" title="Mostrar" style="position: relative; top: 30%; left: 3%;">
</legend>
<div class="tgl" style="display: none;">
<input name="data[Endereco0][id]" id="enderecoID" value="49781" type="hidden">
<div class="input select">
<label for="tipos_enderecoID">Tipo Endereço</label>
<select name="data[Endereco0][tipo_endereco_id]" id="tipos_enderecoID" style="width: 98%">
<option value=""> Selecionar </option>
<option value="1">Residencial</option>
<option value="2">Entrega</option>
<option value="3" selected="selected">Cobrança</option>
<option value="4">Comercial</option>
</select>
</div>
<div class="input text">
<label for="Endereco0Rua">Rua</label>
<input name="data[Endereco0][rua]" value="R SETE DE SETEMBRO" id="Endereco0Rua" type="text">
</div>
<div class="input text">
<label for="Endereco0Numero">Numero</label>
<input name="data[Endereco0][numero]" value="427" id="Endereco0Numero" type="text">
</div>
<div class="input text">
<label for="Endereco0Complemento">Complemento</label>
<input name="data[Endereco0][complemento]" value="Complemento teste" id="Endereco0Complemento" type="text">
</div>
<div class="input text">
<label for="Endereco0Cep">Cep</label>
<input name="data[Endereco0][cep]" value="96015300" id="Endereco0Cep" type="text">
</div>
<div class="input text">
<label for="Endereco0Bairro">Bairro</label>
<input name="data[Endereco0][bairro]" value="CENTRO" id="Endereco0Bairro" type="text">
</div>
<div class="input select">
<label for="estadoID_0">Selecione o Estado</label>
<select name="data[Endereco0][uf]" id="estadoID_0" style="width: 98%">
<option value=""> Selecionar </option>
<option value="IN">IN - Indefinido</option>
<option value="AC">AC - Acre</option>
<option value="AL">AL - Alagoas</option>
<option value="AM">AM - Amazonas</option>
<option value="AP">AP - Amapá</option>
<option value="BA">BA - Bahia</option>
<option value="CE">CE - Ceará</option>
<option value="DF">DF - Distrito Federal</option>
<option value="ES">ES - Espírito Santo</option>
<option value="GO">GO - Goiás</option>
<option value="MA">MA - Maranhão</option>
<option value="MG" selected="selected">MG - Minas Gerais</option>
<option value="EX">EX - Exterior</option>
</select>
</div>
<div class="input select">
<label for="municipioID_0">Selecione a Cidade</label>
<select name="data[Endereco0][municipio_id]" id="municipioID_0" style="width: 98%">
<option value=""> Selecionar </option>
<option value="3" selected="selected">Abadia dos Dourados</option>
<option value="6">Abaeté</option>
<option value="7">Abaeté dos Mendes (Rio Paranaíba)</option>
</select>
</div>
</div>
</fieldset>
<br>
<br>
<fieldset>
<legend style="overflow: hidden;"> Endereço Cobrança<img src="https://cdn2.iconfinder.com/data/icons/icojoy/noshadow/transparent/png/24x24/001_01.png" id="mostraEsconde" alt="Mostrar" title="Mostrar" style="position: relative; top: 30%; left: 3%;">
</legend>
<div class="tgl" style="display: none;">
<input name="data[Endereco1][id]" id="enderecoID" value="50888" type="hidden">
<div class="input select">
<label for="tipos_enderecoID">Tipo Endereço</label>
<select name="data[Endereco1][tipo_endereco_id]" id="tipos_enderecoID" style="width: 98%">
<option value=""> Selecionar </option>
<option value="1">Residencial</option>
<option value="2">Entrega</option>
<option value="3" selected="selected">Cobrança</option>
<option value="4">Comercial</option>
</select>
</div>
<div class="input text">
<label for="Endereco1Rua">Rua</label>
<input name="data[Endereco1][rua]" value="R SETE DE SETEMBRO" id="Endereco1Rua" type="text">
</div>
<div class="input text">
<label for="Endereco1Numero">Numero</label>
<input name="data[Endereco1][numero]" value="427" id="Endereco1Numero" type="text">
</div>
<div class="input text">
<label for="Endereco1Complemento">Complemento</label>
<input name="data[Endereco1][complemento]" value="Complemento teste" id="Endereco1Complemento" type="text">
</div>
<div class="input text">
<label for="Endereco1Cep">Cep</label>
<input name="data[Endereco1][cep]" value="96015300" id="Endereco1Cep" type="text">
</div>
<div class="input text">
<label for="Endereco1Bairro">Bairro</label>
<input name="data[Endereco1][bairro]" value="CENTRO" id="Endereco1Bairro" type="text">
</div>
<div class="input select">
<label for="estadoID_1">Selecione o Estado</label>
<select name="data[Endereco1][uf]" id="estadoID_1" style="width: 98%">
<option value=""> Selecionar </option>
<option value="IN">IN - Indefinido</option>
<option value="AC">AC - Acre</option>
<option value="AL">AL - Alagoas</option>
<option value="AM">AM - Amazonas</option>
<option value="AP">AP - Amapá</option>
<option value="BA">BA - Bahia</option>
<option value="CE">CE - Ceará</option>
<option value="DF">DF - Distrito Federal</option>
<option value="ES">ES - Espírito Santo</option>
<option value="GO">GO - Goiás</option>
<option value="MA">MA - Maranhão</option>
<option value="MG" selected="selected">MG - Minas Gerais</option>
</select>
</div>
</div>
</fieldset>
<br>
<br>
<div class="submit">
<input value="Editar" type="submit">
</div>
</div>
Note: The second item, works normally, the first is that it is bugging...
Man, first look at this mistake:
Uncaught TypeError: Cannot read property 'replace' of undefined
. You are giving this error the moment you click on the icon.– Douglas Garrido
Because it is @Douglasgarrido, I noticed, but I think it is the snippet error, because in my code here is not giving this error. (must be some jquery library)
– Marcos Henzel
Play has code then in a Jsfiddle and see if there is error.
– Douglas Garrido
Blz, I’m gonna test!
– Marcos Henzel