Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

jrlsantana

pegar id da div

Recommended Posts

Pessoal, sou novo no JavaScript, quero uma simples função que ao clicar em um botão ele esconde a div, seu eu passar o id direto na função, funciona normal, mas como esta em um GridView, preciso passar esse id dinamicamente.

 

function Bt1(ids) {
document.getElementById(ids).style.display = "none";
}
HTML
<div id="div1" style="background-image:url('/Images/btn1.png');
background-repeat:no-repeat; cursor:pointer; width:32px; height: 30px;"
onclick="Btn(this)">
</div>

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Qual div sera escondida? Posta um HTML mostrando a estrutura pra saber onde fica o botão e onde fica a div.

Utiliza um serviço como jsbin ou jsfiddle pra postar seu código

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom dia jrlsantana.

Teste este script que montei a partir de sua idéia.

Lembre de chamar o jQuery para usar a função $(this).attr('id') - Esta é a função que pega o atributo ID da sua respectiva DIV.

Se tiver dúvidas estamos à disposição.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>
</head>

<body>
<script type="text/javascript">
function Btn(ids) {
            document.getElementById(ids).style.display = "none";
            document.getElementById(ids).style.visibility = "hidden";
}
</script>
<div id="div1" style="background:#C99; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
<div id="div2" style="background:#06C; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
<div id="div3" style="background:#F39; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
<div id="div4" style="background:#6C3; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
<div id="div5" style="background:#CF3; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
<div id="div6" style="background:#93F; background-repeat:no-repeat; cursor:pointer; width:32px; height:30px;" onclick="Btn($(this).attr('id'))"></div>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.