JavaScript How to append something between a javascript string?

I have a HTML structure like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<table id ="x">
  <tr>
    <td class='col1'>
      Hello <span class='name'></span> How are u ?
    <td>
  </tr>
</table>

And here is my jQuery code:

var variable = $('table#x').find(".col1").html().find("span.name").append(' Jack..!').replace('u', 'you');
alert(variable);

Now, I want this output:

<td class='col1'>Hello <span class='name'>Jack..!</span> How are you ?<td>

How can I do that?

Answer:1

Based on my comment, you could use the following:

Updated Example

$('table#x .col1 span.name').append(' Jack..!').parent().text(function () {
  return $(this).text().replace('u', 'you');
});

There were a couple issues in your code. For one, you can't chain .append() after the .html() method. In addition, the .replace() method wasn't changing the text. To fix this, you could pass an anonymous function to the .text() method and return the replaced text.

Answer:2

I have a form in which certain calculations are happening as per the dropdown selected. Everything is working fine except that when i select a value from dropdown price/unit field has to be filled by ...

I have a form in which certain calculations are happening as per the dropdown selected. Everything is working fine except that when i select a value from dropdown price/unit field has to be filled by ...

sorry but I'm new in javascrit. I'm writing a simple rss reader, but I want to limit the number of feeds to 5 items, because the my target site can have 100 or more. Here the code: $("#mainPage")....

sorry but I'm new in javascrit. I'm writing a simple rss reader, but I want to limit the number of feeds to 5 items, because the my target site can have 100 or more. Here the code: $("#mainPage")....

  1. javascript limit number of characters
  2. javascript limit number of decimals
  3. javascript limit number range
  4. javascript limit number to 2 decimal places
  5. javascript limit number of checkboxes selected
  6. javascript limit number of words
  7. javascript limit number to 1 decimal place
  8. javascript limit number of characters in textbox
  9. javascript limit number of characters in input
  10. javascript limit number
  11. javascript limit number of decimal places
  12. javascript limit number input
  13. javascript limit number length
  14. javascript limit number of digits
  15. javascript limit number of lines in div
  16. javascript limit number to 2 decimals
  17. javascript limit number of lines in textarea
  18. javascript limit number of characters in div
  19. javascript limit number of events
  20. javascript limit number of characters in textarea

Demo link <input type="date" class="datepicker"> $('.datepicker').pickadate({ selectMonths: true, // Creates a dropdown to control month selectYears: 15 // Creates a ...

Demo link <input type="date" class="datepicker"> $('.datepicker').pickadate({ selectMonths: true, // Creates a dropdown to control month selectYears: 15 // Creates a ...

I am facing some issues with the jQuery Chosen plugin. Here are some screenshots: The focused Users input is a jQuery Chosen select input within a tab in a Bootstrap dialog (but this doesn't matter ...

I am facing some issues with the jQuery Chosen plugin. Here are some screenshots: The focused Users input is a jQuery Chosen select input within a tab in a Bootstrap dialog (but this doesn't matter ...

  1. jquery chosen scroll