Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select all elements containing text in ID

I have the following code:

 var aggrHTML = $('TBODY#aggr > tr > td > table > tbody > tr > td > nobr > b');
           var aggrText = aggrHTML.text();
           var newText = "Total" + aggrText.substring(3);
           aggrHTML.html(newText);

What I would like to do is alter the above so I select all elements whose id contain 'aggr'.

Many Thanks, Nav

like image 448
van Avatar asked Nov 19 '10 15:11

van


2 Answers

var aggrHTML = $('TBODY[id*=aggr] > tr > td > table > tbody > tr > td > nobr > b');
           var aggrText = aggrHTML.text();
           var newText = "Total" + aggrText.substring(3);
           aggrHTML.html(newText);
like image 113
Scott Evernden Avatar answered Sep 27 '22 16:09

Scott Evernden


Simplest way to achieve that is

var aggrHTML = $("[id*=aggr]");
var aggrText = aggrHTML.text();
           var newText = "Total" + aggrText.substring(3);
           aggrHTML.html(newText);

If by "all elements" you mean all DOM elements of course.

like image 33
Flipke Avatar answered Sep 27 '22 18:09

Flipke