0

I try to append programaticaly a div that contains a checkbox like this :

appendedDiv = $("<div><input type='checkbox'></div>");
 $(document.body).append(appendedDiv);

In LinkedIn(only in LinkedIn) the checkbox is not shown within the appended div.

When I check in Devtools , the checkbox exists , but isn't shown.

What can be the reason ?

7
  • Is there any CSS that may be hiding it? Are you looking in the right place for it, since it's being appending to the end of the body? Commented Nov 26, 2024 at 19:05
  • It's shown on any other site but LinkedIn. I tried to add "display: visible" style explicitly but witout help. Commented Nov 26, 2024 at 19:31
  • Have you inspected the element to see if there is any CSS that may be hiding it? Commented Nov 26, 2024 at 19:50
  • Yes. It appears in the Elements page of the Devtools but without a border and only when I highlight it. It looks to me something new. Some weeks before , this problem didn't exist. Yet, I try to get a solution. Commented Nov 26, 2024 at 19:54
  • But what CSS has been applied? It's possible LinkedIn has updated their CSS. Commented Nov 26, 2024 at 19:55

1 Answer 1

0

LinkedIn doesn't allow adding buttons and inputs dynamicaly any way, not only as an inner element.
So this is also not allowed :

appendedDiv = $("<input type='checkbox'>");

(Indead I tested only the jQuery way)

The solution

I improvised a checkbox using a canvas element of a squared shape size 13X13px. I used canvas for drawing the 'X' when the square is 'checked'.

appendedDiv = $("<div><canvas id='myCanvas' width='13'; height='13';></canvas>/div>");
$(document.body).append(appendedDiv);
$("#myCanvas").on("click", function() Toggle() });
    

function Toggle(){
    isChecked = !isChecked; // a global toggling flag
    DrawLine(0, 0, 13, 13, isChecked); // The left slash (\) of the X
    DrawLine(0, 13, 13, 0, isChecked); // The right slash            
}

function DrawLine(startX, startY, endX, endY, status) {
                // Get the canvas element and its context
    var canvas = document.getElementById('myCanvas');
    var context = canvas.getContext('2d');
    if (status)
        context.strokeStyle = 'rgb(255, 255, 237)'  // black
    else
        context.strokeStyle = 'rgb(0, 0, 0)';  //white

 // Draw the line
        context.beginPath();
        context.moveTo(startX, startY);
        context.lineTo(endX, endY);
        context.stroke();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.