forum

Home / DeveloperSection / Forums / Why does Jquery only affect the first div element?

Why does Jquery only affect the first div element?

Anonymous User426106-Jun-2013
Hi Expert, 

I am using the "replace" function to remove all non-numeric values in a div.

It seems Jquery replace only affects the first element.

Here is my Jquery:

$('#comment').each(function() {
    var thz = $(this);
    var repl = thz.html(thz.html().replace(/\D+/g, ''));
});

HTML Code:

<a id="comment1" href="#"> c2fđf011. </a>
<a id="comment1" href="#"> c20ff113. </a>
<a id="comment1" href="#"> c201gf76341. </a>

Result:

2011 c20ff113. c201gf76341.

The result I want is:

2011 20113 20176341

Please help,
Thanks in advance. 


Updated on 21-May-2018
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By