Si tengo el siguiente div
<div class = "someclass"> 1234 </div>y un simple botón html en mi sitio. Cuando el usuario hace clic en el botón, quiero ejecutar una función que tomará el contenido de ese div con la clase "alguna clase" (en otras palabras, 1234) y lo agregará a la URL, por ejemplo, https://www.externalsite.com /parameter=(contenido del div) y abre esa url en otra pestaña. Entonces, la URL final es https://www.externalsite.com/parameter=1234 . Todo lo anterior al parámetro en la URL siempre permanece igual. Gracias por adelantado
Puede usar HTMLElement.innerHTML:
let url="https://www.externalsite.com/parameter=" // definie url first part let btn=document.getElementById('click') // get the button element btn.addEventListener('click',function() {url+=document.getElementById('someid').innerHTML}) open(url) <div id = "someid"> <!--the id will be unique, but more element can have the same class attribute--> 1234 </div> <button id="click"></button>