0

My goal is for this code to convert the ".textContent" argument to a method. instead its a string.

`const displayMessage = function (selector, method, message) { document.querySelector(selector) + method + '=' + message; };

displayMessage('p', '.textContent', 'Hello World');`

OJay
  • 63
  • 1
  • 6
  • If the second argument really needs to start with a dot, then something like `document.querySelector(selector)[method.substring(1)] = message`. If the dot isn't necessary, then you can remove the `.substring(1)`. – Ivar Jan 04 '23 at 00:04
  • I tried the code but did work. my expectation is to change the textContent of the paragraph to the passed in argument every time i call the function – OJay Jan 04 '23 at 00:30
  • Yes, it should do just that with the code I've provided. See https://jsfiddle.net/oxgL87ep/1/ – Ivar Jan 04 '23 at 01:01

0 Answers0