Home > Back-end >  change text inside a modal for specific page url using javascript
change text inside a modal for specific page url using javascript

Time:12-12

i am new to javascript and wondering how one would solve the following problem.

on my portfolio website each project has its own page.

i have a button called <button> information </button> . This button is displayed on every page and opens a modal when you click on it. the modal contains information about the project you are currently seeing, e. g. title, year and concept of the work. it is all inside a class called <div id="content"> .

to make it work i added some lines of javascript and it just works fine. however, i now i want all the text inside <div id="content"> to change, depending on the project-page i am currently on.

any ideas on how one could do this?

looking forward to any helpful tip :)

if (window.location="http://anywebadress.com/amazing-project-2") {
 
    title.textContent = "new project-title";
    year.textContent = "new date";

  };

CodePudding user response:

Access the elementById's textContent using querySelector.

var content = document.getElementById("content")
content.querySelector(".title").textContent = title.textContent
content.querySelector(".year").textContent = year.yearContent

CodePudding user response:

// Select the given div
const content = document.getElementById("content") 

// *** now UPDATE ITS CONTENT ***

//            
  • Related