Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

find id attribute that has both phrases inside it

Posted on 2013-02-04
4
219 Views
Last Modified: 2013-02-04
<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
Comment
Question by:knowlton
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38853253
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
 
LVL 5

Author Comment

by:knowlton
ID: 38853334
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
 
LVL 82

Expert Comment

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

$(".myLabelClass").each(function() {
0
 
LVL 5

Author Comment

by:knowlton
ID: 38853345

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question