2
Hello, I made a method in Javascript that when clicking a button is added a text with toggle effect. Only I’m using a function that takes 2 values as arguments to do this, and I can’t use these arguments in jquery selectors.
function adicionaToggle(btnId, pId) {
$('#btnId').click(function() {
$('#pId').toggle();
});
console.log(btnId, pId);
}
$(document).ready(function() {
$('p').hide();
$('button').click(function() {
var btnId = $(this).attr('id');
var pId = $('button').siblings('p').attr('id');
adicionaToggle(btnId, pId);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="div1">
<img src="espaco.jpg" width="300" height="200">
<p id="info1">Blabla</p>
<button id="btn">Mais informações</button>
</div>