0

I have a div .content with an HTML table as a JavaScript String. Within the .content element, there is a td .quantity I need to update the string.

I just tried this:

var content = $('.content').html();
content = $(content).parent().children('.quantity').text("6"); // []
content = $(content).parent().children('.quantity').text("6").html(); // null

I just want to output the string with the update value, kind of like a DOM based search and replace, any ideas?

2 Answers 2

1

Within the .content element, there is a td .quantity I need to update the string.

Try find() method:

var content = $('.content').html();
$(content).find('.quantity').text("6");

You can access it directly too:

$('.content').find('.quantity').text("6");
Sign up to request clarification or add additional context in comments.

2 Comments

this kind of works its giving me <td class="quantity>6</td> but i need the entire table to go back into the content variable.
@ThomasReggi: Reach out the parent table then but try using find method in similar fashion.
1

You could try

var content = $('.content table');
$('.quantity', content).text('6').end(); // will return `table`

DEMO

You can try this to get String

$('.quantity', content).text('6').end().parent().html();

DEMO

2 Comments

I need it returned as a string, how can I do that .html() does not work.
$('.quantity', content).text('6').end(); is an object. I need it to be a string.

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.