• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

find id attribute that has both phrases inside it

<span id="ctl09_gvRepair_ctl03_lblAmt1" style="border: 1px solid green;">1700.00</span>

using jQuery I want to find all spans where the id contains BOTH:

"gvRepair"

and

"lblAmt"

within the same id attribute.


How can I do this?

//pseudocode...
 $('span[id*="lblAmt"]  AND ALSO [id*="gvRepair"] ').each(function () {
0
Tom Knowlton
Asked:
Tom Knowlton
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
sing : http://api.jquery.com/filter/

$('span').filter(function() { return ( $(this).attr("id").indexOf("lblAmt")>=0 ) && ( $(this).attr("id").indexOf("gvRepair")>=0 ); }).each(function () {

Open in new window

0
 
Tom KnowltonWeb developerAuthor Commented:
Yep, it worked.


For my own notes:

   $('span').filter(function() { return ( $(this).attr("id").indexOf("lblAmt")>=0 ) && ( $(this).attr("id").indexOf("gvRepair")>=0 ); }).each(function () {
            subtotRepair += parseFloat($(this).text());
        });

        $('span').filter(function () { return ($(this).attr("id").indexOf("lblAmt") >= 0) && ($(this).attr("id").indexOf("gvRecommended") >= 0); }).each(function () {
            subtotRecommended += parseFloat($(this).text());
        });


        alert(subtotRepair);
        alert(subtotRecommended);

Open in new window

0
 
leakim971PluritechnicianCommented:
if you add a the same class to all your label you should be able to use :

$(".myLabelClass").each(function() {
0
 
Tom KnowltonWeb developerAuthor Commented:

if you add a the same class to all your label you should be able to use :

$(".myLabelClass").each(function() {


Thank you!  I'd forgotten about that!
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now