I have a fetch() running which gets jobs. I'm pulling job descriptions which has HTML tags in them. For example:
I have (snippet of code, full code below):
var description = data.jobs[i].content;
var description = description.replace(/<(.|\n)*?>/g, '');
This prints:
<p><span style="font-weight: 400;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...
It's like the replace function isn't even running?
Code:
fetch('https://boards-api.greenhouse.io/v1/boards/cutover/jobs?content=true', {})
.then(function (response) {
return response.json(); // response type (json)
})
.then(function (data) {
appendDataToHTML(data); // function that appends data to HTML
})
.catch(function (err) {
console.log(err);
});
function appendDataToHTML(data) {
var mainContainer = document.getElementById("jobListing");
// get count of json objs
var data_count = Object.keys(data.jobs).length;
console.log(data_count);
// for each object, create card
for (var i = 0; i < data_count; i++) {
var job_title = data.jobs[i].title;
var job_location = data.jobs[i].location.name;
var job_link = data.jobs[i].absolute_url;
var description = data.jobs[i].content;
var description = description.replace(/<(.|\n)*?>/g, '');
var description = description.substring(0,200);
var html =
'<div class="card">'+
'<div class="card__body">'+
'<div class="card__title">'+ job_title +'</div>'+
'<div class="card__subtitle">'+ job_location +'</div>' +
'<div class="card__copy">'+ description +'</div>'+
'</div>'+
'</div>';
mainContainer.insertAdjacentHTML('beforeend', html);
}
}
<div id="jobListing"></div>
data? Hard to say without seeing the input. What's the expected output?<>will eat part of the content, for instance<p>If a < b but b > c, then...</p>is invalid-but-tolerated-per-spec (yes, really) but will end up asIf a c, then....const div = document.createElement("div"); div.innerHTML = yourHtml; const text = div.textContent;descriptionvariables, when you only want one. Not even sure how this is not throwing an error when you have three variables with the same name.