Using a javascript button to go to the next array in a json object

I have some code that displays an array from a json object based on the id.

I’d like to write a function that allow users to click a button see the next item (id 1), then the one after (id 2), etc. What approach should I take?

JSON:

[
  {
    "id": 0,
    "last_name": "Dan",
    "first_name": "Terry"
  },
  {
    "id": 1,
    "last_name": "Cal",
    "first_name": "Adam"
  },
  {
    "id": 2,
    "year": 2015,
    "last_name": "Brooke",
    "first_name": "Lily"
  }
 ]

JS:

fetch('data.json')
  .then(function (response) {
    return response.json();
  })
  .then(function (data) {
    appendData(data);
  })
  .catch(function (err) {
    console.log(err);
  });


function appendData(data) {
    var mainContainer = document.getElementById("myData");
    var taser
    
    for (var i = 0; i < data.length; i++) {
      if (data[i].id === 0) {      

      var div = document.createElement("div");
      div.innerHTML = data[i].first_name + data[i].last_name;
      mainContainer.appendChild(div);
    }
  }
}

HTML:

<body>
  <div id="myData"></div>

<button id="btn">next</button>
</body>

React Three Fiber Animate when the canvas gets changed

I am using r3f to make a 3d slideshow for when the user click next it slide to the next slideshow but I want to trigger an animation when the user moves to the next slideshow some sort of glitch effect or something and only trigger once the 2nd slideshow appear and when the user switch between slideshows it keeps triggering but only once, here is my code that i use in react , the models is came from react-three/drei library.

  const models = [
    { model : <Sphere/> ,
    }
    ,
    {model : <Box/> ,
   },
   { model: <Sphere/>, 
  },
  { model: <Ring innerRadius={0.5} outerRadius={1} />, 
    }
  ];

  const [modelIndex, setModelIndex] = useState(0);
  const intervalDuration = 5000;
  const modelCount = models.length;

  useEffect(() => {
    const intervalId = setInterval(() => {
      setModelIndex((index) => (index + 1) % modelCount);
    }, intervalDuration);

    return () => clearInterval(intervalId);
  }, [modelCount]);
{models.map((model, index) => (
         index === modelIndex && 
         <div className="canvas-wrapper" key={index}>
            <Canvas key={index}>
            <Environment preset="sunset"/>
            <ambientLight />
            <pointLight position={[10, 10, 10]} />
             <group>
               {model.model}
             </group>
          </Canvas>
         </div>
        ))}

the useEffect hook only helps to change the model every 5s , I want to trigger a shader animation on every canvas created , please how can I achieve that?

Value is not the in list of values of/in classlist, but in first line of console output (js)

i wanted to toggle the “highlighed” class of a td with …classlist.toggle(“highlighed”). now i have the highlighed class in the first line, but not in the detailed description of the console output of the classlist (like in the picture). and i have no idea why.
(just for information: i used the exact same line if code earlier and i worked without problems)
(also i have to say, that this is my first bigger project, so i dont have much experience)

thanks in advance
MW

console output of classlist (which i dont understand)

Import Custom Fonts into Next JS 13

I am having trouble figuring how how to import custom fonts into next js 13. The first problem is that the next js documentation has a thorough example of how to do this with google fonts, but they don’t list anything about using typekit. The other thing is that almost ALL the examples online I have seen talking about this claim to be using Next JS 13, however they all fail to recognize the different between the new App directory and the old Pages directory. Per next js 13 documentation regarding fonts:

While inlining CSS still works in pages (next js v. 12), it does not work in app (next js v. 13). You
should use next/font instead.

So, here is the documentation talking about this new next/font method for version 13:
https://nextjs.org/docs/app/building-your-application/optimizing/fonts

However, this documentation only show how to do google fonts; even the video at the top of the page shows them using the old pages directory.

So, how can I import and use custom TYPEKIT fonts into Next.JS 13 using the new next/font method for the new App directory?

How do I read the link that I am hovering with mouse?

I am not js dev and I tried making a script that lets me hover with a mouse a link in Chrome and when pressing f24 or something open it adding download to the URL. I tried the part of detecting a link and it doesn’t work. This is what I got with ChatGPT.
Any docs or idea that I could read that would help?

// Background script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.action === 'logLink') {
    console.log('Hovered link:', message.url);
  }
});

I tried many different combination of prompts with ChatGPT and I couldn’t make work in the slightest any of them. I use Chrome, I tried with Firefox, neither of them worked. I also tried manifest v2 and v3.

var not defined in JS [duplicate]

Uncaught ReferenceError: posts is not defined
“posts” in case is a var.

Code:

function showPosts() {
    var posts = [
        {
            id: 1,
            title: "Post 1: HTML",
            imageUrl: "assets/card_1_html.png",
            body: "HTML stands for HyperText Markup Language. It is a standard markup language for web page creation. It allows the creation and structure of sections, paragraphs, and links using HTML elements (the building blocks of a web page) such as tags and attributes.",
        },
        {
            id: 2,
            title: "Post 2: CSS",
            imageUrl: "assets/card_2_css.png",
            body: "CSS was developed by W3C (World Wide Web Consortium) in 1996 for a rather simple reason. HTML element was not designed to have tags that would help format the page. You were only supposed to write the markup for the web page.Tags like <font> were introduced in HTML version 3.2, and it caused quite a lot of trouble for web developers. Due to the fact that web pages have different fonts, colored backgrounds, and multiple styles, it was a long, painful, and expensive process to rewrite the code. Thus, CSS was created by W3C to solve this problem.",
        },
        {
            id: 3,
            title: "Post 3: TypeScript",
            imageUrl: "assets/card_3_javascript.png",
            body: "TypeScript is a strongly typed, object-oriented, compiled programming language that builds on JavaScript. It is a superset of the JavaScript language, designed to give you better tooling at any scale. The lead architect behind TypeScript is Anders Hejlsberg, designer of C# at Microsoft. TypeScript is open source, backed by Microsoft, and considered both a language and a set of tools.",
        },
        {
            id: 4,
            title: "Post 4: JavaScript",
            imageUrl: "assets/card_4_typescript.jpg",
            body: "JavaScript is a lightweight programming language that web developers commonly use to create more dynamic interactions when developing web pages, applications, servers, and or even games. Developers generally use JavaScript alongside HTML and CSS The scripting language works well with CSS in formatting HTML elements. However, JavaScript still maintains user interaction, something that CSS cannot do by itself.",
        },
        {
            id: 5,
            title: "Post 5: Git",
            imageUrl: "assets/card_5_git.jpg",
            body: "Git is a mature, actively maintained open source project originally developed in 2005 by Linus Torvalds, the famous creator of the Linux operating system kernel. A staggering number of software projects rely on Git for version control, including commercial projects as well as open source. Developers who have worked with Git are well represented in the pool of available software development talent and it works well on a wide range of operating systems and IDEs (Integrated Development Environments).",
        },
        {
            id: 6,
            title: "Post 6: GitHub",
            imageUrl: "assets/card_6_github.png",
            body: "GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration. GitHub’s interface is user-friendly enough so even novice coders can take advantage of Git. Without GitHub, using Git generally requires a bit more technical savvy and use of the command line.",
        },
    ];
    var postList = document.getElementById("postCard");
    if (postList) {
        postList.innerHTML = "";
        posts.map(function (post) {
            var postContent = document.createElement("a");
            postContent.className = "card";
            postContent.href = "/post_details.html?id=".concat(post.id);
            postContent.innerHTML = "n                <img src="".concat(post.imageUrl, "" alt="post card">n                <h2>").concat(post.title, "</h2>n                <div class="description">n                    <p>").concat(post.body, "</p>n                </div>n                <span>Expand...</span>n            ");
            postList.appendChild(postContent);
        });
    }
}
console.log(posts)

at the moment i’m jsut trying to show “posts” at the console.

How to add different songs to a player in HTML and JavaScript?

I’m struggling to add different songs to a very simple audio-player in HTML and JavaScript.

I’d like to be able to have a bunch of links on the page that would call a function that sets the player’s “src” value, and then play the added song and stop the previous one playing. For some reason it doesn’t work…

HTML:

<body>

<a href="" onclick="setfp(1)">Song 1</a>
<a href="" onclick="setfp(2)">Song 2</a>

<div class="audio-player">
    <div id="play-btn"></div>

    <div class="audio-wrapper" id="player-container" ref="javascript:;">
        <audio id="player">
            <source src="" type="audio/mp3">
        </audio>
    </div>
</div>

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'> 
</script><script  src="./script.js"></script>

</body>

JavaScript:

var sfile = "";

function setfp(song_number)
{
    sfile = "./sf/" + song_number.toString() + ".mp3";  
    alert(sfile);
}

function init()
{
    (function()
        {
            var playerContainer = document.getElementById('player-container');
            var player = document.getElementById('player');
            var isPlaying = false;
            var playBtn = document.getElementById('play-btn');          

            if (playBtn != null)
            {
                playBtn.addEventListener('click', function() {togglePlay()});
            }

            function togglePlay()
            {
                alert(sfile);

                if (player.paused === false)
                {
                    player.pause();
                    isPlaying = false;
                    $('#play-btn').removeClass('pause');
                } else {
                    player.src = sfile;
                    player.play();
                    $('#play-btn').addClass('pause');
                    isPlaying = true;
                }
            }
        }());
}

init();

For some reason, whenever the “play” button is pressed, the value “sfile” is empty even though I set it through the links… I’m new to JavaScript so please help me understand what’s going on… thank you in advance!

How to set corners colision on a graph with Amcharts4?

I want to set corners on this graph to prevent that the circles get cropped when I drag.

Graph from Amcharts docs: https://codepen.io/luizgununes/pen/RwqQmQN

I’ve searched a lot on docs but I didn’t found anything helpful. I’m starting to think this is not possible. Also, I don’t know exactly what is the name of this kind of graph to help searching.

<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/plugins/forceDirected.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></div>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end

var chart = am4core.create("chartdiv", am4plugins_forceDirected.ForceDirectedTree);

var networkSeries = chart.series.push(new am4plugins_forceDirected.ForceDirectedSeries())

networkSeries.data = [{
  name: 'Flora',
  children: [{
    name: 'Black Tea', value: 1
  }, {
    name: 'Floral',
    children: [{
      name: 'Chamomile', value: 1
    }, {
      name: 'Rose', value: 1
    }, {
      name: 'Jasmine', value: 1
    }]
  }]
}, {
  name: 'Fruity',
  children: [{
    name: 'Berry',
    children: [{
      name: 'Blackberry', value: 1
    }, {
      name: 'Raspberry', value: 1
    }, {
      name: 'Blueberry', value: 1
    }, {
      name: 'Strawberry', value: 1
    }]
  }, {
    name: 'Dried Fruit',
    children: [{
      name: 'Raisin', value: 1
    }, {
      name: 'Prune', value: 1
    }]
  }, {
    name: 'Other Fruit',
    children: [{
      name: 'Coconut', value: 1
    }, {
      name: 'Cherry', value: 1
    }, {
      name: 'Pomegranate', value: 1
    }, {
      name: 'Pineapple', value: 1
    }, {
      name: 'Grape', value: 1
    }, {
      name: 'Apple', value: 1
    }, {
      name: 'Peach', value: 1
    }, {
      name: 'Pear', value: 1
    }]
  }, {
    name: 'Citrus Fruit',
    children: [{
      name: 'Grapefruit', value: 1
    }, {
      name: 'Orange', value: 1
    }, {
      name: 'Lemon', value: 1
    }, {
      name: 'Lime', value: 1
    }]
  }]
}, {
  name: 'Sour/Fermented',
  children: [{
    name: 'Sour',
    children: [{
      name: 'Sour Aromatics', value: 1
    }, {
      name: 'Acetic Acid', value: 1
    }, {
      name: 'Butyric Acid', value: 1
    }, {
      name: 'Isovaleric Acid', value: 1
    }, {
      name: 'Citric Acid', value: 1
    }, {
      name: 'Malic Acid', value: 1
    }]
  }, {
    name: 'Alcohol/Fremented',
    children: [{
      name: 'Winey', value: 1
    }, {
      name: 'Whiskey', value: 1
    }, {
      name: 'Fremented', value: 1
    }, {
      name: 'Overripe', value: 1
    }]
  }]
}, {
  name: 'Green/Vegetative',
  children: [{
    name: 'Olive Oil', value: 1
  }, {
    name: 'Raw', value: 1
  }, {
    name: 'Green/Vegetative',
    children: [{
      name: 'Under-ripe', value: 1
    }, {
      name: 'Peapod', value: 1
    }, {
      name: 'Fresh', value: 1
    }, {
      name: 'Dark Green', value: 1
    }, {
      name: 'Vegetative', value: 1
    }, {
      name: 'Hay-like', value: 1
    }, {
      name: 'Herb-like', value: 1
    }]
  }, {
    name: 'Beany', value: 1
  }]
}, {
  name: 'Other',
  children: [{
    name: 'Papery/Musty',
    children: [{
      name: 'Stale', value: 1
    }, {
      name: 'Cardboard', value: 1
    }, {
      name: 'Papery', value: 1
    }, {
      name: 'Woody', value: 1
    }, {
      name: 'Moldy/Damp', value: 1
    }, {
      name: 'Musty/Dusty', value: 1
    }, {
      name: 'Musty/Earthy', value: 1
    }, {
      name: 'Animalic', value: 1
    }, {
      name: 'Meaty Brothy', value: 1
    }, {
      name: 'Phenolic', value: 1
    }]
  }, {
    name: 'Chemical',
    children: [{
      name: 'Bitter', value: 1
    }, {
      name: 'Salty', value: 1
    }, {
      name: 'Medicinal', value: 1
    }, {
      name: 'Petroleum', value: 1
    }, {
      name: 'Skunky', value: 1
    }, {
      name: 'Rubber', value: 1
    }]
  }]
}, {
  name: 'Roasted',
  children: [{
    name: 'Pipe Tobacco', value: 1
  }, {
    name: 'Tobacco', value: 1
  }, {
    name: 'Burnt',
    children: [{
      name: 'Acrid', value: 1
    }, {
      name: 'Ashy', value: 1
    }, {
      name: 'Smoky', value: 1
    }, {
      name: 'Brown, Roast', value: 1
    }]
  }, {
    name: 'Cereal',
    children: [{
      name: 'Grain', value: 1
    }, {
      name: 'Malt', value: 1
    }]
  }]
}, {
  name: 'Spices',
  children: [{
    name: 'Pungent', value: 1
  }, {
    name: 'Pepper', value: 1
  }, {
    name: 'Brown Spice',
    children: [{
      name: 'Anise', value: 1
    }, {
      name: 'Nutmeg', value: 1
    }, {
      name: 'Cinnamon', value: 1
    }, {
      name: 'Clove', value: 1
    }]
  }]
}, {
  name: 'Nutty/Cocoa',
  children: [{
    name: 'Nutty',
    children: [{
      name: 'Peanuts', value: 1
    }, {
      name: 'Hazelnut', value: 1
    }, {
      name: 'Almond', value: 1
    }]
  }, {
    name: 'Cocoa',
    children: [{
      name: 'Chocolate', value: 1
    }, {
      name: 'Dark Chocolate', value: 1
    }]
  }]
}, {
  name: 'Sweet',
  children: [{
    name: 'Brown Sugar',
    children: [{
      name: 'Molasses', value: 1
    }, {
      name: 'Maple Syrup', value: 1
    }, {
      name: 'Caramelized', value: 1
    }, {
      name: 'Honey', value: 1
    }]
  }, {
    name: 'Vanilla', value: 1
  }, {
    name: 'Vanillin', value: 1
  }, {
    name: 'Overall Sweet', value: 1
  }, {
    name: 'Sweet Aromatics', value: 1
  }]
}];

networkSeries.dataFields.linkWith = "linkWith";
networkSeries.dataFields.name = "name";
networkSeries.dataFields.id = "name";
networkSeries.dataFields.value = "value";
networkSeries.dataFields.children = "children";
networkSeries.links.template.distance = 1;
networkSeries.nodes.template.tooltipText = "{name}";
networkSeries.nodes.template.fillOpacity = 1;
networkSeries.nodes.template.outerCircle.scale = 1;

networkSeries.nodes.template.label.text = "{name}"
networkSeries.fontSize = 8;
networkSeries.nodes.template.label.hideOversized = true;
networkSeries.nodes.template.label.truncate = true;
networkSeries.minRadius = am4core.percent(2);
networkSeries.manyBodyStrength = -5;
networkSeries.links.template.strokeOpacity = 0;

How to create a draggable carousal slide with an unordered list inside the slides?

I require some assistance in creating a unordered list (with dropdowns) inside a draggable carousal slide.

You will see that I am unable to access the dropdown menu when clicking on the list item. What could I do to resolve the below issue?

Sample Photo

You will see that I was able to create the unordered list inside the carousal, however, I am just experiencing display issues.

Sample Code: JSFiddle.

const carousel = document.querySelector('.carousel');
const slidesContainer = carousel.querySelector('.carousel-container');
const slides = Array.from(carousel.querySelectorAll('.carousel-slide'));
const arrowLeft = carousel.querySelector('.carousel-arrow.left');
const arrowRight = carousel.querySelector('.carousel-arrow.right');
let currentIndex = 0;
let isDragging = false;
let startPos = 0;
let currentTranslate = 0;
let prevTranslate = 0;

function handleDragStart(event) {
  isDragging = true;
  startPos = getPositionX(event);
  prevTranslate = currentTranslate;
  slidesContainer.style.transition = 'none';
}

function handleDragMove(event) {
  if (!isDragging) return;
  const currentPosition = getPositionX(event);
  currentTranslate = prevTranslate + currentPosition - startPos;
  setSliderPosition();
}

function handleDragEnd() {
  isDragging = false;
  const slideWidth = slides[0].offsetWidth;
  if (currentTranslate < -slideWidth / 4) {
    currentIndex += 1;
  } else if (currentTranslate > slideWidth / 4) {
    currentIndex -= 1;
  }
  slidesContainer.style.transition = 'transform 0.4s ease-in-out';
  setSliderPosition();
}

function setSliderPosition() {
  slidesContainer.style.transform = `translateX(${currentTranslate}px)`;
}

function getPositionX(event) {
  return event.type.includes('mouse') ? event.pageX : event.touches[0].clientX;
}

function showSlide(index) {
  currentIndex = index;
  currentTranslate = -slides[currentIndex].offsetLeft;
  slidesContainer.style.transform = `translateX(${currentTranslate}px)`;
}

function slideToNext() {
  if (currentIndex === slides.length - 1) {
    currentIndex = 0;
  } else {
    currentIndex += 1;
  }
  showSlide(currentIndex);
}

function slideToPrev() {
  if (currentIndex === 0) {
    currentIndex = slides.length - 1;
  } else {
    currentIndex -= 1;
  }
  showSlide(currentIndex);
}

arrowLeft.addEventListener('click', slideToPrev);
arrowRight.addEventListener('click', slideToNext);

slidesContainer.addEventListener('mousedown', handleDragStart);
slidesContainer.addEventListener('touchstart', handleDragStart);
slidesContainer.addEventListener('mousemove', handleDragMove);
slidesContainer.addEventListener('touchmove', handleDragMove);
slidesContainer.addEventListener('mouseup', handleDragEnd);
slidesContainer.addEventListener('touchend', handleDragEnd);
slidesContainer.addEventListener('mouseleave', handleDragEnd);
.carousel {
  width: 600px;
  height: auto;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.carousel-container {
  display: flex;
  width: 100%;
  margin-bottom: 10px;
}

.carousel-slide {
  flex: 0 0 100%;
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.carousel-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.carousel-arrow.left {
  left: 10px;
}

.carousel-arrow.right {
  right: 10px;
}

.nav-list {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-list li {
  margin-right: 10px;
}

.dropdown-menu {
  position: absolute;
  z-index: 9999;
}
<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>

<body>
  <div class="carousel">
    <div class="carousel-container">
      <div class="carousel-slide">
        <img src="https://via.placeholder.com/50" alt="Slide 1">
        <ul class="nav nav-list">
          <li class="nav-item">
            <a class="nav-link" href="#">Item 1</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 1
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown1">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown2" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 2
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown2">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
        </ul>
      </div>
      <div class="carousel-slide">
        <img src="https://via.placeholder.com/50" alt="Slide 2">
        <ul class="nav nav-list">
          <li class="nav-item">
            <a class="nav-link" href="#">Item 1</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown3" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 1
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown3">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown4" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 2
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown4">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
        </ul>
      </div>
      <div class="carousel-slide">
        <img src="https://via.placeholder.com/50" alt="Slide 3">
        <ul class="nav nav-list">
          <li class="nav-item">
            <a class="nav-link" href="#">Item 1</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown5" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 1
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown5">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="dropdown6" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              Dropdown 2
            </a>
            <div class="dropdown-menu" aria-labelledby="dropdown6">
              <a class="dropdown-item" href="#">Dropdown Item 1</a>
              <a class="dropdown-item" href="#">Dropdown Item 2</a>
              <a class="dropdown-item" href="#">Dropdown Item 3</a>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="carousel-arrow left">&lt;</div>
    <div class="carousel-arrow right">&gt;</div>
  </div>

  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>

How to Replace Word in code with Typed in text?

I’m in need of a code where people can type in a word that replaces a certain “key” word with whatever they typed in. For context, I have a website where I provide donacode (Episode app) templates for users to copy and paste and use. However, the code requires people to replace a certain word with their own word. Right now I’ve instructed people to copy/paste code into a document and use Ctrl+F to replace all. But I want them to be able to just type in their word on my website then click on a generate button, and then the words in my code get changed to whatever they type in.

So far I’ve got this cooked up, but it only allows me to change 1 word, instead of multiple words at a time. If anyone can please help me out so that ALL key words get changed and not just 1 word, please that would be awesome!

<p id="upper">Type your character's name in all CAPS.</p>
<input type="text" id="inp">
<button id="btn" onclick="changeImage()"> Change Character Name </button>

<script>
  function changeImage() {
    var enteredText = inp.value;
    charname.innerText = enteredText;
  }
</script>

</br>
</br>
<span id="charname">CHARACTER</span> enters from left to screen center

React-google-maps not displaying props

I am trying to display a simple Circle on the map using the Circle prop. It works perfectly fine on one computer using chrome however it will not display on the map when on another computer using the same browser.

The circle only displays after I manually force a rerender – example by creating a second circle my page refreshes and shows the intended circle on the map.

However once i refresh the browser window the circle disapears.

I have tried adding a Zindex without any luck, I have also tried using the newer useJsApiLoader rather than but am experiencing the same issue.

import React, { useRef } from 'react';
import { GoogleMap, LoadScript, StandaloneSearchBox, Circle } from '@react-google-maps/api';

const EndpointMap = () => {

  const searchBoxRefLocation = useRef(null);
  const mapRef = useRef(null); // Reference to Google Map component
  const apiKey = 'myKey';

  return (
    <LoadScript googleMapsApiKey={apiKey} libraries={['places']}>
      <div style={{ height: '100vh', width: '100vw' }}>
        <GoogleMap
          ref={mapRef}
          mapContainerStyle={{ height: '100vh', width: '100vw' }}
          center={{ lat: 49.3, lng: -123.2194 }}
          zoom={8}
        >
        <Circle
        center={{ lat: 49.2, lng: -123.2194 }}
        radius={10000}
        options={{
            strokeColor: '#FF0000',
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: '#FF0000',
            fillOpacity: 0.1,
        }}
        />
        </GoogleMap>
      </div>
    </LoadScript>
  );
};
export default EndpointMap;

How can I Integrate Duffel Payments (using UMD module) if I am using python in the backend?

I don’t know how to write the two required functions bellow that can achieve the goes started in the commented text.
Api Guidelines: https://duffel.com/docs/guides/collecting-customer-card-payments#collect-payment
The Payment Component
The Api has no examples of implementation.

I want the component to render on the screen. I have managed to generate the payment intent in the flask back-end and pass it to the front-end using flask render_template() method as a valuable and then retrieve it in the front end using jinja. That is all I know. I am a newbie please help me with implementation examples, including how to write:

  1. successfulPaymentHandlerFn.
  2. errorPaymentFn.

trying to make an automatic image slider with js

hi so i have this code but its not working, right now the sliding of images is manual and by clicking on buttons but i wanna automate it in a way that it changes to the second pic on its own, i got an image container that moves back and forth on X axis meaning its left property changes from 240px(when its displaying the first image) to 518px (when its displaying the second image). so in order to automate that process i wrote this script to assign the left position of image container to variable “pos” and checks to see if its at 240 which is the position for the first image, if so changes it to 518 to display sec image and vice versa, but it doesnt work.
i wanna know what the issue is:

        <script>
        document.addEventListener('DOMContentLoaded', function(){
            const pos=document.getElementById("imagecontainer").getBoundingClientRect().left;
            console.log(pos)

            if(pos=="240"){
                document.getElementById("imagecontainer").style.left="518px";
                const pos=document.getElementById("imagecontainer").getBoundingClientRect().left;

            }
            else if(pos=="518"){
                document.getElementById("imagecontainer").style.left="240px";
                const pos=document.getElementById("imagecontainer").getBoundingClientRect().left;


            }
        });
    </script>
</head>
<body>
    <p id="a">hello</p>
    <div class="slider">
        <span id="slide1"></span>
        <span id="slide2"></span>
        <div id="imagecontainer">
            <img src="/images/im1.jpg" class="img" width="500" height="300">
            <img src="/images/p1.jpg" class="img" width="500" height="300">
        </div>
        <div class="buttons">
            <a href="#slide1"></a>
            <a href="#slide2"></a>
        </div>  
    </div>
</body>

Related posts in Next.js markdown blog

I have a website under development on next.js . a blog is already ready there. I am wondering if it is possible to make a blog of similar articles that are on many sites. The tag that is assigned to the article can serve as a filter. I will show my article component [slug.js]

import { getAllPosts, getPostBySlug } from "@/lib/getAllData";
import Seo from "@/components/global/seo";
import { serialize } from 'next-mdx-remote/serialize';
import { MDXRemote } from 'next-mdx-remote';

import Link from 'next/link'
import Date from '@/lib/date';
import styles from "@/styles/home/posts.module.css"
import PostFooter from "@/components/extra/postFooter"

import Button from '@/components/button';

const _ = require("lodash")
import {translit} from "@/lib/utils"

const components = {
    Button
}

const blogPostHeaderTopTagClasses = [styles.blogPostHeaderTopTag, "mainBtn"].join(" ")

const getTagLink = (tag) => {
    return (
        <Link className={blogPostHeaderTopTagClasses} href={`/blog/tag/${tag}`} key={tag}>
            {translit(tag)}
        </Link>
    );
};

const posts = getAllPosts();

export async function getStaticPaths() {

    return {
        paths: posts.map((post) => {
            return {
                params: {
                    slug: post.slug,
                },
            };
        }),
        fallback: false,
    };
}


  export async function getStaticProps({ params: { slug } }) {
    const post =  getPostBySlug(slug);
    const mdxSource = await serialize(post.content);

    const postIndex = posts.findIndex((post) => post.slug === slug)
    const prev = posts[postIndex + 1] || null
    const next = posts[postIndex - 1] || null

    return {
      props: {
        post,
        frontmatter: post.data,
        content: mdxSource,
        prev,
        next
      }
    };
  }


  export default function PostPage({ frontmatter, content, prev, next }) {

    const url = typeof window !== 'undefined' ? window.location.href : '';

    return (
        <>

            <Seo
                title={`${frontmatter.title}`}
                description={`${frontmatter.description}`}
                canonicalUrl={url}
                ogImageUrl={`http://localhost:3000/api/og?title=${frontmatter.title}&description=${frontmatter.description}&date=${frontmatter.date}`}
                ogType={"article"}
            />

            <article className={styles.blogPost}>
                <div className="wrapper">
                    <header className={styles.blogPostHeader}>
                        <div className={styles.blogPostHeaderTop}>
                            {frontmatter.tags.map(tag => getTagLink(tag)).reduce((prev, curr) => [prev, '', curr])}
                        </div>
                        <h1 className={styles.blogPostTitle}>{frontmatter.title}</h1>
                        <p className={styles.postDesc}>{frontmatter.description}</p>
                        <span className={styles.blogPostHeaderDate}>
                            <Date dateString={frontmatter.date} />
                        </span>
                    </header>
                </div>
                <div className="wrapperRead">
                    <MDXRemote {...content}  components = {components} />
                    <PostFooter
                        title={frontmatter.title}
                    />
                    {(next || prev) && (
                    <div className={styles.prevNextPosts}>
                        {prev && (
                            <div className={styles.prevNextPostsItem}>
                                <h6>
                                    Предыдущая статья
                                </h6>
                                <h5>
                                    <Link className={styles.prevNextPostsItemLink} href={`/blog/${prev.slug}`}>{prev.title}</Link>
                                </h5>
                            </div>
                        )}
                        {next && (
                            <div className={styles.prevNextPostsItem}>
                                <h6>
                                    Следующая статья
                                </h6>
                                <h5>
                                    <Link className={styles.prevNextPostsItemLink} href={`/blog/${next.slug}`}>{next.title}</Link>
                                </h5>
                            </div>
                        )}
                    </div>
                    )}
                </div>
            </article>
      </>
    );
  }

Let’s say embed the related posts block under the (next|| prev) block. I need to somehow match one of the tags that the currently open article has and other articles that have one of the same tags. Is the information provided by the code above enough, or is something else needed? Who will tell you what to do?