Satch3000 Satch3000 - 2 years ago 114
Javascript Question

Javascript self hide parent div not hiding when span clicked

I have a div that's been created dynamically. Multiple of them are created and I need to do a self parent hide, so this is what I've done:

This Div:

<div><a href="">'+inputText+'-</a><div class="box"></div><span onclick="dismiss();">Close</span></div>

The Function:

function dismiss() {

It's not hidding when I click the close span.

Answer Source

Inside dismiss function this refers to window object, instead pass the this as an argument .

function dismiss(ele) {
<script src=""></script>
<div><a href="">'+inputText+'-</a>
  <div class="box"></div><span onclick="dismiss.bind(this);dismiss(this);">Close</span>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download