Solved

find id attribute that has both phrases inside it

Posted on 2013-02-04
4
208 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

932 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now