Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

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 () {
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

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

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

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

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!