Note that there are some explanatory texts on larger screens.

plurals
  1. POhiding parent element of a element passed as argument in the JavaScript function
    text
    copied!<p>I have a app where i have to show a timer for a event,and when the event is over , that timer (block containing it) should hide. i have set the CSS for the parent div element(that block) as the timer element has dynamic id(it has the id no of the events along with classname). </p> <p>this is JavaScript code:</p> <pre><code>function GetCount(deal_year,deal_month,deal_date,deal_box) { dateFuture = new Date(deal_year,deal_month,deal_date,00,00,00); // alert(dateFuture); return false; dateNow = new Date(); //grab current date //alert(dateNow); span = dateFuture.getTime() - dateNow.getTime(); //calc milliseconds between dates delete dateNow; // if date has passed if(span &lt;= 0){ x=document.getElementById("dealbox"); x.parentNode.getAttributeNode("style").value="display:none"; } else { // date is still good // convert from milliseconds to hr/m/s... // and save them in diff variable(code is long so avoided that) document.getElementById(deal_box).innerHTML="&lt;span&gt;"+out+" &lt;/span&gt;&lt;br/&gt;&lt;strong&gt;days : hours : minutes : seconds&lt;/strong&gt;"; setTimeout("GetCount('"+deal_year+"','"+deal_month +"','"+deal_date+"','"+deal_box+"')", 1000); </code></pre> <p>Ans this is the php code </p> <pre><code> if(strtotime("now") &lt; strtotime($end_date)) { ?&gt; &lt;div class ="timer_box" id="timer" style="float:right; display: block;" &gt; &lt;b&gt;&lt;div id="deal_box&lt;?php echo $id; ?&gt;"&gt;&lt;/div&gt;&lt;/b&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; GetCount(&lt;?php echo $timer_array[0]; ?&gt;,&lt;?php echo $timer_array[1]-1; ?&gt;,&lt;?php echo $timer_array[2]; ?&gt;,'&lt;?php echo 'deal_box'.$id; ?&gt;','&lt;?php echo 'timer'; ?&gt;'); &lt;/script&gt; &lt;?php } ?&gt; </code></pre> <p>i tried hiding the parent block by using parentNode access of DOM element passed into the function. But it didn't work. I suspect that function is not able to access if of the parent through the element. I tried every thing , but no help. so tried workaround of changining the class name of the element by javascript, but still think there shd be a better method,as i am noob n hopefully missing something. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload