[jQuery] Re: jQuery Selector Help
[ ... snipped ... ] ... and after looking at your code (which always helps), I see you're referencing this (as opposed to jQuery's $(this)), which is why html() wouldn't have worked. In that case, sure. It's been said that this is more efficient than creating a jQuery reference to it via $(this). So to clarify... this.innerHTML is the functional equivalent of $(this).html(), but without the cost of creating a new jQuery object for each iteration of your each(). [ ... snipped ... ] Thanks for the explanation. I went back and cleaned up my code to use jQuery(this).html() instead of this.innerHTML and all is well. Mike
[jQuery] jQuery Selector Help
Long time listner, first time caller ... I am struggling with a selctor and am hopeful someone can help me see the forest through the trees. I am using a WordPress plugin which generates the following HTML: td class=day-with-date span class=weekend26/span span class=eventbr / * span class=calnk nowrap=nowrap a href=# style=Christmas Break span style= div class=event-titleChristmas Break/div div class=event-title-break/div/span/a/spanbr / * span class=calnk nowrap=nowrap a href=http://localhost/?p=104; style= Futsal Training span style= div class=event-titleFutsal Training/div div class=event-title-break/divstrongTime:/strong 1:30 pmbr / div class=event-content-break/div Futsal Training at NetSports /span /a /span /span /td I want to strip the asterisk characters (*) from the HTML. I have been able to tweak a few things but I am struggling with a selctor which would allow me to eliminate the asterisk. Any help or suggestions would be approeciated. I was trying to do this but innerHTML returns undefined and I am not sure why. jQuery('span.even br').each(function() { html = this.innerHTML ; // Some manipulation goes here jQuery(this).html(html) ; } I am by no means a jQuery guru so I am sure I am missing something obvious. Thanks, Mike
Re: [jQuery] jQuery Selector Help
I would suggest you to wrap the sections within * into a div and select that div. Thanks Regards, Dhruva Sagar. On Tue, Dec 22, 2009 at 6:29 PM, Mike Walsh mike_wa...@mindspring.comwrote: Long time listner, first time caller ... I am struggling with a selctor and am hopeful someone can help me see the forest through the trees. I am using a WordPress plugin which generates the following HTML: td class=day-with-date span class=weekend26/span span class=eventbr / * span class=calnk nowrap=nowrap a href=# style=Christmas Break span style= div class=event-titleChristmas Break/div div class=event-title-break/div/span/a/spanbr / * span class=calnk nowrap=nowrap a href=http://localhost/?p=104; style= Futsal Training span style= div class=event-titleFutsal Training/div div class=event-title-break/divstrongTime:/strong 1:30 pmbr / div class=event-content-break/div Futsal Training at NetSports /span /a /span /span /td I want to strip the asterisk characters (*) from the HTML. I have been able to tweak a few things but I am struggling with a selctor which would allow me to eliminate the asterisk. Any help or suggestions would be approeciated. I was trying to do this but innerHTML returns undefined and I am not sure why. jQuery('span.even br').each(function() { html = this.innerHTML ; // Some manipulation goes here jQuery(this).html(html) ; } I am by no means a jQuery guru so I am sure I am missing something obvious. Thanks, Mike
[jQuery] Re: jQuery Selector Help
On Dec 22, 8:03 am, Dhruva Sagar dhruva.sa...@gmail.com wrote: I would suggest you to wrap the sections within * into a div and select that div. Thanks Regards, Dhruva Sagar. [ ... snipped ... ] Unfortunately I don't have control of the generated content. The content is generated by a WordPress Calendar plugin that I am reluctant to modify which is why I would like to find a way to do this with jQuery. Mike
[jQuery] Re: jQuery Selector Help
Well, you selected BR elements, which are empty elements, so it's no mystery why this.innerHTML returns undefined... Also, DIVs shouldn't appear inside SPANs...
Re: [jQuery] Re: jQuery Selector Help
2009/12/22 Šime Vidas sime.vi...@gmail.com Well, you selected BR elements, which are empty elements, so it's no mystery why this.innerHTML returns undefined... Also, DIVs shouldn't appear inside SPANs... He did state that he's using generated HTML. He has no control over it. Mike - this isn't really a jQuery problem per se. You're jQuery selectors match DOM elements. Not so much the contents of those elements. What you can do is search for the containing element (in this case, you can look for a span with a class of event), and replace all instances of br /* with just the br /. $(document).ready(function() { var newHTML = $('span.event').html().replace(/(br.*)\s*\*/g, '$1'); $('span.event').html(newHTML); }); The expression is looking for a br / (or br or br/) followed by any white space (including tabs), followed by an asterisk. It replaces that pattern with the br / alone (removing the asterisk). Disclaimer: I'm no regex guru, so if anyone sees a way to clean up that expression, please feel free. -- Charlie Griefer http://charlie.griefer.com/ I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success.
[jQuery] Re: jQuery Selector Help
On Dec 22, 12:09 pm, Charlie Griefer charlie.grie...@gmail.com wrote: 2009/12/22 Šime Vidas sime.vi...@gmail.com Well, you selected BR elements, which are empty elements, so it's no mystery why this.innerHTML returns undefined... Also, DIVs shouldn't appear inside SPANs... He did state that he's using generated HTML. He has no control over it. Mike - this isn't really a jQuery problem per se. You're jQuery selectors match DOM elements. Not so much the contents of those elements. What you can do is search for the containing element (in this case, you can look for a span with a class of event), and replace all instances of br /* with just the br /. $(document).ready(function() { var newHTML = $('span.event').html().replace(/(br.*)\s*\*/g, '$1'); $('span.event').html(newHTML); }); The expression is looking for a br / (or br or br/) followed by any white space (including tabs), followed by an asterisk. It replaces that pattern with the br / alone (removing the asterisk). [ ... snipped ... ] Thanks for pointing me in the right direction. This is what I ended up getting to work: jQuery(span.event, .calendar-table).each(function(){ var html = this.innerHTML.replace(/(br\s*\/*)\s*\*/ g, \'$1\'); jQuery(this).html(html) ; }) ; I changed the regular expression slightly to eliminate the .* portion and changed .html() to .innerHTML. I don't know enough jQuery to know why I had to do that but had seen it elsewhere so tried it and it worked. Thanks, Mike
Re: [jQuery] Re: jQuery Selector Help
On Tue, Dec 22, 2009 at 10:34 AM, Mike Walsh mike_wa...@mindspring.comwrote: [ ... snipped ... ] Thanks for pointing me in the right direction. This is what I ended up getting to work: jQuery(span.event, .calendar-table).each(function(){ var html = this.innerHTML.replace(/(br\s*\/*)\s*\*/ g, \'$1\'); jQuery(this).html(html) ; }) ; I changed the regular expression slightly to eliminate the .* portion and changed .html() to .innerHTML. I don't know enough jQuery to know why I had to do that but had seen it elsewhere so tried it and it worked. Thanks, Mike .html() retrieves the innerHTML. Really no functional difference, but for the sake of consistency, since you're leveraging jQuery, I'd prefer to see consistent jQuery code (unless there's a compelling reason not to). And yeah... just a preference. Not saying wrong or right. But I am saying you shouldn't have -had- to do that :) Anyway, glad you got it working. That's the important bit :) -- Charlie Griefer http://charlie.griefer.com/ I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success.
Re: [jQuery] Re: jQuery Selector Help
On Tue, Dec 22, 2009 at 10:40 AM, Charlie Griefer charlie.grie...@gmail.com wrote: On Tue, Dec 22, 2009 at 10:34 AM, Mike Walsh mike_wa...@mindspring.comwrote: [ ... snipped ... ] Thanks for pointing me in the right direction. This is what I ended up getting to work: jQuery(span.event, .calendar-table).each(function(){ var html = this.innerHTML.replace(/(br\s*\/*)\s*\*/ g, \'$1\'); jQuery(this).html(html) ; }) ; I changed the regular expression slightly to eliminate the .* portion and changed .html() to .innerHTML. I don't know enough jQuery to know why I had to do that but had seen it elsewhere so tried it and it worked. Thanks, Mike .html() retrieves the innerHTML. Really no functional difference, but for the sake of consistency, since you're leveraging jQuery, I'd prefer to see consistent jQuery code (unless there's a compelling reason not to). And yeah... just a preference. Not saying wrong or right. But I am saying you shouldn't have -had- to do that :) Anyway, glad you got it working. That's the important bit :) ... and after looking at your code (which always helps), I see you're referencing this (as opposed to jQuery's $(this)), which is why html() wouldn't have worked. In that case, sure. It's been said that this is more efficient than creating a jQuery reference to it via $(this). So to clarify... this.innerHTML is the functional equivalent of $(this).html(), but without the cost of creating a new jQuery object for each iteration of your each(). -- Charlie Griefer http://charlie.griefer.com/ I have failed as much as I have succeeded. But I love my life. I love my wife. And I wish you my kind of success.
Re: [jQuery] Selector Help
That's a nice solution. Let's make it easier to follow with some indentation: $('a.filter').click(function() { $(this) .closest('ul') .children() .removeClass('active') .end() .end() .closest('li') .addClass('active'); }); The basic indentation rules we're following here are: * Put each method call on a line by itself, with the . at the beginning of the line. (You can put more than one call on the same line, but only when they don't change the selection.) * Where a method creates the jQuery object or changes its element selection, indent the next line. * Where .end() is called, un-indent that line. You could even go overboard on readability and add the missing .end() calls at the very end: $('a.filter').click(function() { $(this) .closest('ul') .children() .removeClass('active') .end() .end() .closest('li') .addClass('active') .end() .end(); }); Now this looks a lot like the way we indent blocks in JavaScript and other languages. Each .closest() or .children() call is matched up with its own .end() call - as is the initial $(this) - and the indentation indicates the code affected by each of those calls. It's more customary to omit those trailing.end() calls, but with or without them, the indentation is a great help in visualizing the structure of a complex chain. -Mike On Sun, Nov 29, 2009 at 11:39 PM, Michel Belleville michel.bellevi...@gmail.com wrote: Even better : $('a.filter').click(function() { $(this).closest('ul').children().removeClass('active').end().end().closest('li').addClass('active'); }); Michel Belleville 2009/11/29 Mauricio (Maujor) Samy Silva css.mau...@gmail.com Try this: $('a.filter').click(function(){ $(this).parent().siblings('li').removeClass('active'); $(this).parent('li').addClass('active'); }); Maurício -Mensagem Original- *De:* Charlie charlie...@gmail.com *Para:* jquery-en@googlegroups.com *Enviada em:* domingo, 29 de novembro de 2009 03:56 *Assunto:* Re: [jQuery] Selector Help ... Dave Maharaj :: WidePixels.com wrote: How would I go about adding class to the li in this set up? lia href=# class=filterspanall/span/a/li lia href=# class=filterspansome/span/a/li lia href=# class=filterspannone/span/a/li ...
RE: [jQuery] Selector Help
Good, practical formatting for understand the chain From: Michael Geary [mailto:m...@mg.to] Sent: Monday, November 30, 2009 3:28 AM To: jquery-en@googlegroups.com Subject: Re: [jQuery] Selector Help That's a nice solution. Let's make it easier to follow with some indentation: $('a.filter').click(function() { $(this) .closest('ul') .children() .removeClass('active') .end() .end() .closest('li') .addClass('active'); }); The basic indentation rules we're following here are: * Put each method call on a line by itself, with the . at the beginning of the line. (You can put more than one call on the same line, but only when they don't change the selection.) * Where a method creates the jQuery object or changes its element selection, indent the next line. * Where .end() is called, un-indent that line. You could even go overboard on readability and add the missing .end() calls at the very end: $('a.filter').click(function() { $(this) .closest('ul') .children() .removeClass('active') .end() .end() .closest('li') .addClass('active') .end() .end(); }); Now this looks a lot like the way we indent blocks in JavaScript and other languages. Each .closest() or .children() call is matched up with its own .end() call - as is the initial $(this) - and the indentation indicates the code affected by each of those calls. It's more customary to omit those trailing.end() calls, but with or without them, the indentation is a great help in visualizing the structure of a complex chain. -Mike On Sun, Nov 29, 2009 at 11:39 PM, Michel Belleville michel.bellevi...@gmail.com wrote: Even better : $('a.filter').click(function() { $(this).closest('ul').children().removeClass('active').end().end().closest(' li').addClass('active'); }); Michel Belleville 2009/11/29 Mauricio (Maujor) Samy Silva css.mau...@gmail.com Try this: $('a.filter').click(function(){ $(this).parent().siblings('li').removeClass('active'); $(this).parent('li').addClass('active'); }); Maurício -Mensagem Original- De: Charlie mailto:charlie...@gmail.com Para: jquery-en@googlegroups.com Enviada em: domingo, 29 de novembro de 2009 03:56 Assunto: Re: [jQuery] Selector Help ... Dave Maharaj :: WidePixels.com wrote: How would I go about adding class to the li in this set up? lia href=# class=filterspanall/span/a/li lia href=# class=filterspansome/span/a/li lia href=# class=filterspannone/span/a/li ...
Re: [jQuery] Selector Help
Try this: $('a.filter').click(function(){ $(this).parent().siblings('li').removeClass('active'); $(this).parent('li').addClass('active'); }); Maurício -Mensagem Original- De: Charlie Para: jquery-en@googlegroups.com Enviada em: domingo, 29 de novembro de 2009 03:56 Assunto: Re: [jQuery] Selector Help ... Dave Maharaj :: WidePixels.com wrote: How would I go about adding class to the li in this set up? lia href=# class=filterspanall/span/a/li lia href=# class=filterspansome/span/a/li lia href=# class=filterspannone/span/a/li ...
Re: [jQuery] Selector Help
Even better : $('a.filter').click(function() { $(this).closest('ul').children().removeClass('active').end().end().closest('li').addClass('active'); }); Michel Belleville 2009/11/29 Mauricio (Maujor) Samy Silva css.mau...@gmail.com Try this: $('a.filter').click(function(){ $(this).parent().siblings('li').removeClass('active'); $(this).parent('li').addClass('active'); }); Maurício -Mensagem Original- *De:* Charlie charlie...@gmail.com *Para:* jquery-en@googlegroups.com *Enviada em:* domingo, 29 de novembro de 2009 03:56 *Assunto:* Re: [jQuery] Selector Help ... Dave Maharaj :: WidePixels.com wrote: How would I go about adding class to the li in this set up? lia href=# class=filterspanall/span/a/li lia href=# class=filterspansome/span/a/li lia href=# class=filterspannone/span/a/li ...
[jQuery] Selector Help
How would I go about adding class to the li in this set up? lia href=# class=filterspanall/span/a/li lia href=# class=filterspansome/span/a/li lia href=# class=filterspannone/span/a/li $('a.filter').click(function(){ $(???).addClass('active'); }); Thanks Dave
Re: [jQuery] Selector Help
$('a.filter').click(function(){ $(this).parent().addClass('active'); }); Dave Maharaj :: WidePixels.com wrote: How would I go about adding class to the li in this set up? lia href="" class="filter"spanall/span/a/li lia href="" class="filter"spansome/span/a/li lia href="" class="filter"spannone/span/a/li $('a.filter').click(function(){ $(???).addClass('active'); }); Thanks Dave
[jQuery] Selector help needed
with the markup like: prelt;ulgt; lt;ligt;lt;a href=quot;#quot;gt;Link 1lt;/agt;lt;/ligt; lt;ligt; lt;a href=quot;#quot;gt;Link 2lt;/agt; lt;ulgt; lt;ligt;lt;a href=quot;#quot; class=quot;activequot;gt;Link 2.1lt;/agt;lt;/ligt; lt;ligt;lt;a href=quot;#quot;gt;Link 2.2lt;/ agt;lt;/ligt; lt;/ulgt; lt;/ligt; lt;/ulgt; /pre i want to add a class active to , Link 2 (line 4), or links that have inner a.active links. how can i do it with jquery or even pure css?
[jQuery] Selector help
I'm pretty new to Javascript/ jQuery, so this is really bugging me. I'm trying to get the height of an h1 that is a sibling to this. The value for the variable h1Height, however, returned as null in the console in Firebug. Perplexed, I tried console.logging ('this'+'+h1') to see what it was interpreted as. It brought back this+h1, which should select an h1 adjacent to this (which is a div). Javascript h1Height = $('this'+'h1').height(); What went wrong?
[jQuery] Selector help
I am cleaning up some html code and originally i had li div class=loading id=loading_profile/div div id=profile dl class=entry dtProfile Settings/dt dd class=skills ?php foreach ($user['Preferences'] as $preference): echo $preference['name'] . ', '; endforeach; ? /dd /dl /div /li but the DIV inside the LI was too much so I went with adding the id=profile to LI but script is no longer working li id=profile div class=loading id=loading_profile/div div dl class=entry dtProfile Settings/dt dd class=skills ?php foreach ($user['Preferences'] as $preference): echo $preference['name'] . ', '; endforeach; ? /dd /dl /li SCRIPT: $(a[class^='edit_']).click(function(){ var url_id = $(this).attr('href'); var x = $(this).attr('id').split('_'); var y = x[0]; var z = x[1]; $(#loading_+z).show(fast, function() { $(#+z).slideUp( 1000, function(){ $(.edit_+z).hide(0.1, function() { $(#+z).load( url_id , function(){ $(#+z).slideDown( 1000, function() { $(#loading_+z).hide(function(){ $(#+z).fadeTo(fast, 1, function() { $(#+z).fadeIn(slow); }); }); }); return false; }); }); }); }); }); Do i eed to edit the selecot as li#? Dave
[jQuery] Selector help needed
Here's my code: $(document).ready(function(){ $('#menulinks a').hover(function(){ setTimeout(function(){ $(this).stop().animate({ top : '40px', paddingTop : '40px' }); }, 1000); }); }); Before I added a timeout, (this) sufficed. With the timeout set, (this) did not select the hovered link. I tried another selector and it worked fine. How can I specify (this) for this situation? -- View this message in context: http://www.nabble.com/Selector-help-needed-tp23289341s27240p23289341.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] jQuery Selector Help
Hi, Can some1 please explain this in detail to me? I am confused on the selector part $('li id=_img'+index+'/li'). // add list to ul var list = $('li id=_img'+index+'/li').attr ('class',_imageLoadClassName).appendTo('ul#'+_imgContainerId); Thanks!
[jQuery] Selector Help
I have a table structure with a multiple rows containing a checkbox input and 4 text inputs with distinct classes. I want to prefill two of the text inputs in the same row where the checkbox is checked. Example code for the first two rows: table tr id=row1 tdinput type=checkbox //td tdinput type=text class=email //td tdinput type=text class=contact //td tdinput type=text class=realname //td tdinput type=text class=sport //td /tr tr id=row2 tdinput type=checkbox //td tdinput type=text class=email //td tdinput type=text class=contact //td tdinput type=text class=realname //td tdinput type=text class=sport //td /tr /table I need help me crafting the correct selector to focus control onto the text input for the input with class=contact and class=email. I can write the function to manipulate the attributes but I can't figure out the selector. I haven't had any luck with prev ~ siblings or prev + next. Thanks in advance.
[jQuery] Selector help
I'm using a attribute selector and I want to combine the *= with the ! = on href. Is there any way to do this?
[jQuery] Selector Help
Code: fieldset a href= class=link/a /fieldset fieldset a href= class=link/a /fieldset fieldset a href= class=link/a /fieldset When a link is clicked, I would like to be able to reference the particular parent fieldset element, and not all of them. Something like this doesn't work: $('.link').click(function () { $(this+':parent').BLAHBLAHBLAH(); }); Thanks in advance, the help here is top notch!
[jQuery] Selector help needed
Hi All, This is my DOM structure: tr class=child1 td class=titleCellFirst Name:/td td class=fieldCellinput class=inputbox value=John //td /tr tr class=child1 td class=titleCellMiddle Name:/td td class=fieldCellinput class=inputbox value=Garry //td /tr tr class=child2 td class=titleCellFirst Name:/td td class=fieldCellinput class=inputbox value=Nick //td /tr tr class=child2 td class=titleCellMiddle Name:/td td class=fieldCellinput class=inputbox value=Peter //td ... Questions: 1) how can I select the value Garry? I tried $('tr.child1 td input').eq(1).value But it does not work 2) How can I reset all values of input fields of tr.child2 without cycling through? Any help? -- View this message in context: http://www.nabble.com/Selector-help-needed-tp17508515s27240p17508515.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] selector help
My app has to present some rather lengthy list of choices. Each choice has a checkbox tied to it and multiple choices can be made. When 'editting' the choices, we want to see all available choices, but after editting is done, we only want to see what was selected. I'm stuck coming up with the jQuery selector to display the user choices. Something like this:. $('TR',list).hide().filter(':has([EMAIL PROTECTED])').show(); -- View this message in context: http://www.nabble.com/selector-help-tp17369737s27240p17369737.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Selector help
I'm either making this more difficult than it is, or I'm missing something simple... I have a div that contains a table. Inside that table I have rows with an arbitrary number of cells. The cells may or may not contain a div with a tasksummary class. I need to find all the rows that DO NOT have a task summary div, and toggle them. I can easily find the tasksummaries: $(#containerDiv table tbody tr .tasksummary); But how do I change this to give me the TR's that don't have a task summary div? (note, some of the cells may contain sub tables, so the explicit tabletbodytr isolates only the main table...) The only method I can see right now is to find the TRs then do a .each() on them and check each row with the .hasClass(). But I'm sure there's an easier way... Thanks for any input. Shawn
[jQuery] Selector Help - hover and dblclick
In a table like this: table id=choices-table border=1 width=75% trthItem/th/tr tr id=row-1tdOne/td/tr tr id=row-2tdTwo/td/tr tr id=row-3tdThree/td/tr /table I want to highlight the rows when hovered. I also wan't to set a different background color on the row when double clicked. I have the following jquery code: $(document).ready( function() { $([EMAIL PROTECTED]'']).hover( function(){ $(this).addClass('hilite'); }, function(){ $(this).removeClass(); }); $([EMAIL PROTECTED]'']).dblclick(function(){ $(this).removeClass(); $(this).addClass('dblclckd'); }); } ); Note: in the above selectors that is @class=single quotesingle quote The hover is highlighting the rows. The double-click is changing the row background. The problem is when if I hover over the previously double clicked row. It loses its styling. What I'd like to do is prevent the hover from acting on any row that has been double clicked. I'm trying to do this based on the hovered rows class, but that isn't working. Ultimately, I'd also like to prevent the double clicked row from running code if previously double clicked.
[jQuery] Selector help - All inputs except radio buttons?
I currently have this? var params = $('input,select,textarea').serialize(); Is there a simple way to serialize all inputs expect for radio buttons?