Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-3-7-sonnet-20250219-thinking-32k· AnthropicHugging Face LMArena Human Preference 140K

im trying to set a paragraph text via js, but this would ruin the formatting of a bold…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash’s answer.
  1. User

    im trying to set a paragraph text via js, but this would ruin the formatting of a bold tag. how can i solve this?

  2. Claude Assistant

    To set paragraph text via JavaScript while preserving bold formatting, you should use the innerHTML property instead of textContent:

    // This will preserve HTML formatting like bold tags
    document.getElementById('myParagraph').innerHTML = 'This is my text with <b>bold words</b> in it.';
    
    // Instead of:
    // document.getElementById('myParagraph').textContent = 'This is my text with <b>bold words</b> in it.';
    // which would display the literal <b> tags
    

    Alternatively, you can create and append elements programmatically:

    const paragraph = document.getElementById('myParagraph');
    paragraph.textContent = ''; // Clear existing content
    
    // Add regular text
    paragraph.appendChild(document.createTextNode('This is my text with '));
    
    // Add bold text
    const boldElement = document.createElement('b');
    boldElement.textContent = 'bold words';
    paragraph.appendChild(boldElement);
    
    // Add more regular text
    paragraph.appendChild(document.createTextNode(' in it.'));
    

    Would you like me to explain or break down the code?

  3. User

    but i have the already the bold tag, something like this: <p id='sets'><b>sets: </b></p>, and via js it would be something like this: node.textContent += variable. i need something that would work with a similar solution

  4. Claude Assistant

    If you already have a structure like <p id='sets'><b>sets: </b></p> and want to append text after the bold tag without disturbing it, try this approach:

    // Append text after the bold tag while preserving formatting
    document.getElementById('sets').appendChild(document.createTextNode(variable));
    

    This will keep your existing bold tag intact and add the new content after it.

    Alternatively, you could use:

    // Another approach using insertAdjacentHTML
    document.getElementById('sets').insertAdjacentHTML('beforeend', variable);
    

    Both solutions maintain your existing HTML structure while adding new content after the bold element.

    Would you like me to explain or break down the code?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.