1

I have a string like below,

var markup = "<p class='error-info-popup-link' onclick='processData.getErrorInfoPopup("+helper.qaConstants[item.errors[i]]+", "+item.source+", "+ seqNo +")'> Info </p>"

Above string output is:-

<p class="error-info-popup-link" onclick="processData.getErrorInfoPopup(Numeric Mismatch, 1, 2)"> Info </p> 

I want below output:-

<p class="error-info-popup-link" onclick="processData.getErrorInfoPopup('Numeric Mismatch', 1, 2)"> Info </p>

What should i do?

1
  • You can use \" to escape quotes in a string Commented Sep 18, 2019 at 14:51

2 Answers 2

1

Just add the escaped quotes:

var markup = "<p class='error-info-popup-link' onclick='processData.getErrorInfoPopup(\""+helper.qaConstants[item.errors[i]]+"\", "+item.source+", "+ seqNo +")'> Info </p>"

Or use templates:

var markup = `<p class='error-info-popup-link' onclick='processData.getErrorInfoPopup("${helper.qaConstants[item.errors[i]]}", ${item.source}, ${seqNo})'> Info </p>`
Sign up to request clarification or add additional context in comments.

Comments

1

Personally I would say bypass the issue entirely and avoid inline bindings.

var newP = document.createElement('p');

newP.classList.add('error-info-popup-link');
newP.innerText = ' Info ';
newP.addEventListener('click', function(){
  processData.getErrorInfoPopup(
    helper.qaConstants[item.errors[i]],
    item.source,
    seqNo
  );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.