I am trying to get the following simple function to open divs with the same name of the grabbed “name” attributes in other divs, any help would be appreciated.
<script type="text/javascript">
$(document).ready(function(){
$('.div').click(function(){
var nip = (this).attr("name");
$('#nip').show()
})
});
</script>
Use
$(this).attr("name")instead of(this).attr("name")to get the name. Then, use$('#' + nip)to select the desired element.Your current selector does not work, because the variable name is contained within quotes, causing
"nip"to be literally interpreted as"nip".