Prompt Title: Convert HTML to JS.

Created 1 year ago
Votes 0
Views 249 times
0

Prompt Detail:

You can't convert HTML code directly into JavaScript, but you can use JavaScript to create HTML elements dynamically.

Here's a simple JavaScript script that does the same thing as your HTML code:

javascript
// create the div element var div = document.createElement("div"); div.style.position = "fixed"; div.style.right = "0px"; div.style.bottom = "0px"; div.style.width = "70px"; div.style.marginRight = "2.5rem"; div.style.marginBottom = "3rem"; // create the anchor element var a = document.createElement("a"); a.href = "https://api.whatsapp.com/send?phone=212600000000"; // create the image element var img = document.createElement("img"); img.src = "https://cdn4.iconfinder.com/data/icons/social-media-flat-7/64/Social-media_Whatsapp-512.png"; // append the img to the anchor a.appendChild(img); // append the anchor to the div div.appendChild(a); // append the div to the body document.body.appendChild(div);

The above script will append the WhatsApp icon to your web page when the script is run.

Make sure to run the script after the DOM is fully loaded. If you want to make sure the DOM is ready before you add the element, you could wrap the above code in a function and call it when the 'DOMContentLoaded' event fires:

javascript
document.addEventListener("DOMContentLoaded", function() { // put the code here });
avatar
w
Shared 3 prompts
Created 1 year ago

Leave a Comment

Related Tag Prompts

94
0
151
0
Docker Pro
1 year ago 2023-01-29 06:08:59 AIPRM
308
0
MySQL Marvel
1 year ago 2023-02-13 00:05:32 AIPRM
260
0
Ansible Expert
1 year ago 2023-02-01 09:23:50 AIPRM
193
0
PostgreSQL Pro
1 year ago 2023-02-07 03:45:19 AIPRM
114
0
270
1
Dockerize me
1 year ago 2023-02-17 08:27:58 Chad Thompson-Smith