Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
Changing the class of a div inside a label and the contents of a div inside that div is causing the checkbox associated with that label to uncheck.
Post Body

HTML like so:

<input type='checkbox' name='example3' id='example3' class='examplesection'>
<label for='example3' class='examplesection'>
    <div class='examplecontent'>
        Lorem ipsum dolor
        <img src='someimage.png'>
        A man a plan a canal Panama
        <div id='example3demo' class='example3X'> //<--This is our canvas in the JS below
                Ia Cthulu.
                <div class='example3stuffhappens'>
                   #A bunch of HTML is in here.
               </div>
       </div>
    </div>
</label>

CSS (Doesn't really matter, but maybe helpful to see what the CSS is doing)

input.examplesection {
    display:none;
}

input.examplesection   label.examplesection  {
  /*Some stuff that shows the title and hides the rest of the contents.*/
}

input.examplesection:checked   label.examplesection {
    /*Some stuff that desplays the label contents and changes the background color... It's a collapsible section in pure CSS. */
}

JavaScript:

if(flags.includes('example3')){
    document.getElementById("example3demo").classList.remove("example3X");
    document.getElementById("example3demo").classList.add("example3Y");

    canvas = document.getElementById("example3stuffhappens");

    //Clear out the contents of canvas.
    canvas.innerHTML="";
   //Repopulate canvas with the new content
   x3cont = document.createElement("div"); 
   for( //loopconditions) {
        x3cont.appendChild(//lotsofstuff);
   }
   canvas.appendChild(x3cont);

}

That's what's happening. If the "flags" array contains "example3", the script triggers and changes the class of the "example3demo" element, then loops through a set of conditions, populates a div it made with a bunch of child elements, then pushes that div into

The problem is, that when this happens, the demo3 checkbox becomes unchecked, thus collapsing the demosection and hiding the result from the user. They can go click on the section and it will open back up and show them the expected change, but this terrible UX.

I had an idea that as part of the "if()" I could try to get the "example3" checkbox and set it's state to checked,which I imagine would cause the user to see the section collapse and then reexpand, showing the change. Better, but not perfect. I haven't tried to implement it yet. To add to the complexity of this solution the "example3" id is actually generated dynamically and if other contents on the page change it might become "example4" or "example2". That's out of my control unless I hack the PHP that's generating the HTML (which has it's own set of problems... like when the script updates).

Is there a better solution to pursue? Why is this happening at all? Is there a way I can just stop it from happening?

Author
Account Strength
100%
Account Age
14 years
Verified Email
Yes
Verified Flair
No
Total Karma
70,349
Link Karma
11,188
Comment Karma
58,740
Profile updated: 5 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago