Solved

Please help with changing child div class

Posted on 2011-09-12
12
303 Views
Last Modified: 2012-05-12
In the following html:

<div id="ctl00_TopCart2_upCart">
		
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td class="TopCartCellAlign">
                        <div class="TopCartImageAlign"><a id="ctl00_TopCart2_hlViewCart" href="CartDetails.aspx"><img src="App_Themes/utenn/Images/cart.gif" alt="view cart" style="border-width:0px;" /></a></div>
                    </td>
                    <td class="TopCartCellAlign">

                        <span id="ctl00_TopCart2_lblTotalItems" class="TopCartItemsCountNumberDisplayed">0</span>
                        <span id="ctl00_TopCart2_Label1" class="TopCartItemsCountText">Item(s) totaling</span>
                        <span id="ctl00_TopCart2_lblTotalAmount" class="TopCartTotalAmount">$0.00</span>
                        
                    </td>
                </tr>
            </table>
        
	</div>

Open in new window




I need to change the styling for the div with class "TopCartImageAlign" to "SpecialTopCartCellAlign"

                    <td class="TopCartCellAlign">
                        <div class="TopCartImageAlign"><a id="ctl00_TopCart2_hlViewCart" href="CartDetails.aspx"><img src="App_Themes/utenn/Images/cart.gif" alt="view cart" style="border-width:0px;" /></a></div>
                    </td>


changes to:


                    <td class="SpecialTopCartCellAlign">
                        <div class=""><a id="ctl00_TopCart2_hlViewCart" href="CartDetails.aspx"><img src="App_Themes/utenn/Images/cart.gif" alt="view cart" style="border-width:0px;" /></a></div>
                    </td>




Must "td" have an id asigned for this to work?


There is also the following restriction:

-the div must be a descendant (child or grandchild) of a div with id containing the words "TopCart2"


0
Comment
Question by:knowlton
  • 6
  • 6
12 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36523637
What about :
$(".TopCartImageAlign").removeClass("TopCartImageAlign").addClass("SpecialTopCartCellAlign");
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36523682
or (you change name of the class in your question, first time TopCartImageAlign and after : TopCartCellAlign) :
$(".TopCartCellAlign").removeClass("TopCartCellAlign").addClass("SpecialTopCartCellAlign");
0
 
LVL 5

Author Comment

by:knowlton
ID: 36523683
TopCartImageAlign is used in other places and I don't want it changed in those places....just where the class "TopCartImageAlign" has a parent div with an id containing "TopCart2".

So changing the assigned div for say "TopCart1" would not be desired.

:)
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36523704
   $(".TopCartImageAlign", "div[id*='TopCart2']").removeClass("TopCartImageAlign").addClass("SpecialTopCartCellAlign");
0
 
LVL 5

Author Comment

by:knowlton
ID: 36523739
I noticed you use two params in the first part:

  $(".TopCartImageAlign", "div[id*='TopCart2']").

Can you tell me more about what each param is for?  I mean, I think I know...but can you talk about a it some?
0
 
LVL 5

Author Comment

by:knowlton
ID: 36523749
I was thinking about trying this:


  //$('div[id*="TopCart2"] > ')  blah blah

Would this be valid as well?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 82

Expert Comment

by:leakim971
ID: 36523752
could you confirm it work first? thanks
0
 
LVL 5

Author Comment

by:knowlton
ID: 36523808
Works just great!!
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 36523814
thx
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36523861
$(".TopCartImageAlign", "div[id*='TopCart2']") similar to :
$("div[id*='TopCart2']").find(".TopCartImageAlign")
this return an array of jQuery object

removeClass and addClass is applied to all the jQuery objects of this array.

Check this page : http://api.jquery.com/jQuery/ 
jQuery( selector, [ context ]  )

my favorite page : http://api.jquery.com/category/selectors/
0
 
LVL 5

Author Comment

by:knowlton
ID: 36523973
LK:


Thank you so much for this information!

I welcome any other sites you use on a regular basis for jQuery type questions, if you want to share additional sites!!


I own the following books by O'Reilly which are great:

http://www.amazon.com/jQuery-Cookbook-Solutions-Examples-Developers/dp/0596159773

and

http://www.amazon.com/jQuery-Pocket-Reference-David-Flanagan/dp/1449397220/ref=sr_1_1?s=books&ie=UTF8&qid=1315845020&sr=1-1


but sometimes you are still a lot faster.   :)

0
 
LVL 82

Expert Comment

by:leakim971
ID: 36524385
yeah, I've some O'Reilly books, I love them too (Java, Oracle, TCP/IP, ...)

I found all the infos I need on the jQuery site itselft or for UI : http://jqueryui.com/
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 74
Syntax error in this jQuery codes 6 21
combining jquery scripts 3 21
JQuery Make Input Inactive based upon class value 2 26
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now