[jQuery] Re: Having problems getting index() and closest() to work
I am not sure of the functions you have used, 'index' and 'closest', I have not seen them, atleast it is not part of the cheat sheet I use. ok, the following code could solve your problem, //1) get the quantity above the price that is clicked var tableDom = $(this).parents('table')[0]; var quant = tableDom.rows[0].cells[this.cellIndex].innerHTML; console.log(quant); //2) get the content of the heading above the relevant table var h2heading = $(this).parents('table').prevAll('h2').eq(0).text(); console.log(h2heading); you can also address issue 1 by using the data() function that is available in jquery, but you would have to loop through your data to spit out the jquery that will do this. hope this helps On Feb 5, 6:19 am, paulswansea sendtoswan...@hotmail.com wrote: Hi, I have a page with multiple tables, and need to get the index value of a cell with a price which i click on, so i can extract the relevent quantity within the row above, i've tried using the index() function but to no avail! also, I wish to extract the content of the previous h2 header, i'm not sure if closest('h2') is the best way to do it, but it also doesn't work, could someone please tell me how to do this? Please see below for the code (note that there is roughly about ten tables to which i've cut down to two for here, also I CANNOT change the tables i.e. add id or classes anywhere, so the tables have to stay the way they are, I just need to get some jquery code to work around this and extract the relevant data). So a brief run down of what i need to do : 1) get the quantity above the price that is clicked 2) get the content of the heading above the relevant table THE CODE : h2 class=sublistingFirst Item Named here/h2 pinformation goes here/p table class=price_table tr th Quantity/th th 1000 /th th 5000 /th th 10,000 /th th 15,000 /th th 20,000 /th /tr tr td Price /td tdstrong£400/strongbr / span class=each_item40p each/span/td tdstrong£1650/strongbr / span class=each_item33p each/span/td tdstrong£3200/strongbr / span class=each_item32p each/span/td tdstrong£4800/strongbr / span class=each_item32p each/span/td tdstrong£6200/strongbr / span class=each_item31p each/span/td /tr /table h2 class=sublistingsecond Item Named here/h2 pinformation goes here/p table class=price_table tr th Quantity/th th 1000 /th th 5000 /th th 10,000 /th th 15,000 /th th 20,000 /th /tr tr td Price /td tdstrong£400/strongbr / span class=each_item40p each/span/td tdstrong£1650/strongbr / span class=each_item33p each/span/td tdstrong£3200/strongbr / span class=each_item32p each/span/td tdstrong£4800/strongbr / span class=each_item32p each/span/td tdstrong£6200/strongbr / span class=each_item31p each/span/td /tr /table script type=text/javascript //![CDATA[ $('.each_item').parent().click( function() { var indexvar = $(this).parent().index(this); /* NOT WORKING / var headerval = $(this).closest('h2').text(); /** ALSO NOT WORKING **/ var quantity = $(tbodyvar).children('tr').children('th').eq (indexvar).text(); alert('Requested ' + quantity + ' of ' + headerval); }); //]] /script
[jQuery] Re: access table row[y] cell[x]
try $(#myTable tr:eq(4) td:eq(1)).html() for the 5th row and 2nd column On Feb 2, 5:46 am, JAS james.sch...@gmail.com wrote: I am (very) new to jQuery, and I have what I think must be a simple question. Without jQuery, I would write: var oCell = document.getElementById('myTable').rows[5].cells [2].innerHTML = something new; but I do not understand how to write this same line in jQuery. Thanks to anyone who can help. JAS
[jQuery] Re: Strange .attr('src') behavior in IE
I tried it too, and jquery is not consistent in handling the href/src attribute in IE. I don't know why it is giving the absolute url when a/img tags are loaded via ajax. @MorningZ , the topic you have linked to, suggests that using $ (this).attr(href) will always give the actual text in href attribute and not the absolute url, but that is only partially true, if the link/ image is loaded via ajax call, then in IE it gives the absolute url. The same is true for src attribute too. I hope the jquery team finds a way to fix this. Spaceage In the meantime how about using something like this, I know this is not as concise as your version, but it will work independat of the browser. arrOldImage = $(this).attr(src).split(/); arrOldImage[arrOldImage.length-1] = arrOldImage [arrOldImage.length-1].split(.).join(-hover.); newImage = arrOldImage.join(/); $(this).attr(src,newImage); ksun On Jan 29, 9:26 am, MorningZ morni...@gmail.com wrote: I wouldn't call it strange, as IE automatically appends the full domain name on any link anyways, this topic from earlier in the week deals with this exact issue http://groups.google.com/group/jquery-en/browse_thread/thread/7d53af6... On Jan 28, 10:49 pm, spaceage spaceageliv...@gmail.com wrote: I have a hover script that implements image rollovers that goes like this: $(document).ready(function() { $(img.rollover).hover(function() { $(this).attr(src, $(this).attr(src).split(.).join(- hover.)); }, function() { $(this).attr(src, $(this).attr(src).split(-hover.).join (.)); }); }); This works great in all browsers--I just use a class=rollover on the img and name the rollover image with a -hover before the extension. Oddly, in IE6/7, when I jQuery load a div with new img elements and reapply the hover function to the new img elements, IE gets screwed up on the src setting. It seems that IE uses the full domain name as the source, and so my src ends up incorrect as - hover. gets appended to every item in the src prior to a .. eg: after a load command (where the src attributes are relative, ie. '/ images/myimage.jpg'), I end up with an image src of: http://www-hover.mysite-hover.com/images/myimage-hover.jpg This only happens on IE 6/7 and only after a load event. I use the exact same code on normal http page fetch to build these images in my div, and this script works fine--the -hover only gets appended at the file name of the src. Does anybody have any idea why this is happening in IE? Thanks in advance.- Hide quoted text - - Show quoted text -
[jQuery] Re: High Point Village Website
Could see only intro in IE On Jan 29, 12:58 pm, kim3er rich...@dogma.co.uk wrote: Hi, I've just finished working on a new web site using jQuery 1.3.1 and would appreciate feedback. http://www.highpointvillage.co.uk/ Rich
[jQuery] Re: insert div into group ordered by ID..
try this, it will insert gamma1 before epsilon. $('#gamma~#epsilon').before('div id=gamma1/'); I first used after(), but that didn't work, looks like $ ('#gamma~#epsilon') selects #epsilon. On Dec 22, 10:48 am, Tbone 95dak...@gmail.com wrote: I'm a relative newbie with jQuery and have read the doc about DOM manipulation but am too dense to answer this question: I have a series of DIVs in order by ID. I would like to insert a new DIV into its proper place in the order... Given the following: div div id=alpha/div div id=beta/div div id=gamma/div div id=epsilon/div /div How would I be able to insert the following div in its correct spot (between gamma and epsilon)? div id=alpha/div Thanks in advance!
[jQuery] Re: insert div into group ordered by ID..
//locate the div before which you want to insert and then insert, assuming they are ordered alphabetically $('div[id]').each(function(){ if ($(this).attr('id') 'delta') $(this).before('div id=delta/'); }); I think there is no selector that will do the same, but I may be wrong. On Dec 22, 12:32 pm, Tbone 95dak...@gmail.com wrote: Great! Thanks... However, I'm more clueless than I should be...and didn't pose the complete question... I have the divs as shown above, how do I locate where div id=delta/div would go? Obviously between gamma and epsilon, but I need to search the ids for the first (id delta). Then I can use your insert to properly place it. I assume I use a selector, but am not sure how to put it together. On Dec 22, 10:25 am, ksun kavi.sunda...@gmail.com wrote: try this, it will insert gamma1 before epsilon. $('#gamma~#epsilon').before('div id=gamma1/'); I first used after(), but that didn't work, looks like $ ('#gamma~#epsilon') selects #epsilon.- Hide quoted text - - Show quoted text -
[jQuery] Re: Simple FadeIn with Appending
This is one way to do it. Not sure if it can be done more elegantly. script $(document).ready(function() { $('label').after('span style=display:none/span'); $('#button').click(function(){ $('label :input').each(function(){ if (!$(this).parent().next('span').text()) $(this).parent().next('span').text('You need to enter ' + this.name + ' here'); if (!$(this).val()) $(this).parent().next('span').fadeIn('slow'); else $(this).parent().next('span').hide(); }); }); }); /script /head body labelLabel1: input name=label1 type=text //label br/ labelLabel2: input name=label2 type=text //label br / button id=buttonClick/button On Dec 11, 4:30 pm, WhoButSB whobu...@gmail.com wrote: The variable fieldName is something that I'am pulling in from somewhere else. Here is the full code: if(val == ''){ var fieldName = $(select[name='fieldcategoryID'] :selected).text(); $(#fieldValue label).fadeIn('slow', function (){ $(this).after(span class='field-error'You need to enter a +fieldName+ here./span);}); return false; //Send the data to the servers }else{ What I would like to do is have the error message fade In above after the label, if the person enters an empty value in to a input box. I'm just unsure what the syntax order is for the fadeIn() and after() methods. Thanks for the help. On Dec 11, 1:03 pm,ksunkavi.sunda...@gmail.com wrote: $(this).after(span class='field-error'You need to enter a +fieldName+ here./span); What is fieldName, you need get that value from somewhere, before trying to use it. Also the effect is applied only on the object on which it is called, so if your label is hidden then it will appear slowly. The span tag will just appear, it will not have the fadeIn effect. I am not sure what exactly you are trying to achieve here, but hope this helps. On Dec 11, 11:24 am, WhoButSB whobu...@gmail.com wrote: Hello all, I have a really simple question but, and once I figure out this little hurdle I know I will be able to work on a lot more stuff. I would like to add a simple notification to fade in when some one presses a button but I would like to attach the notification after a label. I know I have to be really close with this code I just can't figure it out. $(function(){ $('#button').click(function(){ $(#fieldValue label).fadeIn('slow', function (){ $(this).after(span class='field-error'You need to enter a +fieldName+ here./span); }); }); }); Thanks for your help!- Hide quoted text - - Show quoted text -
[jQuery] Re: Simple FadeIn with Appending
$(this).after(span class='field-error'You need to enter a +fieldName+ here./span); What is fieldName, you need get that value from somewhere, before trying to use it. Also the effect is applied only on the object on which it is called, so if your label is hidden then it will appear slowly. The span tag will just appear, it will not have the fadeIn effect. I am not sure what exactly you are trying to achieve here, but hope this helps. On Dec 11, 11:24 am, WhoButSB [EMAIL PROTECTED] wrote: Hello all, I have a really simple question but, and once I figure out this little hurdle I know I will be able to work on a lot more stuff. I would like to add a simple notification to fade in when some one presses a button but I would like to attach the notification after a label. I know I have to be really close with this code I just can't figure it out. $(function(){ $('#button').click(function(){ $(#fieldValue label).fadeIn('slow', function (){ $(this).after(span class='field-error'You need to enter a +fieldName+ here./span); }); }); }); Thanks for your help!
[jQuery] Re: Potential Bug when .append (ing) html and then selecting on it?
$(this).children('span a').click(function() This is not allowed, you can only select the immediate children, so you have to do it twice I guess. I am not sure if there is a better way. Also I used toggle function instead of click, that lets you run 2 functions alternatively. Also using next instead of siblings. Here is my code $(document).ready(function() { $('h4.filteredResultsTitle').each(function() { $(this).append(' span class=show(a href=#show/a)/ span'); $(this).next('ul').hide(); $(this).children('span').children('a').toggle( function() { $(this).parent().parent().next('ul').show(); $(this).text('hide'); return false; }, function() { $(this).parent().parent().next('ul').hide(); $(this).text('show'); return false; } ); }); On Dec 11, 8:53 am, sironf...@msn.com sironf...@msn.com wrote: I have the follow HTML markup h4 class=filteredResultsTitleInformation Sources/h4 ul style=display: block; li.../li li.../li li.../li /ul I'm trying to create show/hide buttons against the 'Information Sources' h4 element to toggle the ul element to disappear/ reappear. So far I have the following jquery $(document).ready(function() { $('h4.filteredResultsTitle').each(function() { $(this).append(' span class=show(a href=#show/a)/ span'); $(this).siblings('ul').hide(); $(this).children('span a').click(function() { $(this).parent().parent().siblings('ul').show(); $(this).text('hide'); return false; }); }); }); This doesn't seem to work though. However, if I change $(this).parent ().parent().siblings('ul').show(); into $(this).parent().siblings ('ul').show(); (remove a call the .parent() ) it does work, but surely this is incorrent as the markup is... h4Title span class=show(a href=#show/a)/span/h4 ...and the parent of a is span and the parent of span is h4, yet it seems to jump straight from a to h4 missing out the span when I remove a call to .parent(). What's more my click event is getting applied to the span and not the a as $(this).text('hide') causes the brackets and the ashow/a to be completely replaced. I remember a work colleague telling me that JQuery does have problems trying to select on elements that have been dynamically created (such as when using .append() in my case). Is this a know issue with JQuery, or am I totally doing something wrong. Cheers!
[jQuery] Re: newbie: unfold form on checkbutton
I think I like this one better. Removed the anchor tag, and used this.checked (DOM object) I tend to rewrite stuff a lot with Jquery, I guess thats part of the learning. script $(document).ready(function() { $(':checkbox').click(function(){ if(this.checked) $('#showtime').show(); else $('#showtime').hide(); }); }); /script /head body INPUT TYPE=checkbox NAME=limit VALUE=yIset report period/ I div id=showtime [] /div On Dec 11, 3:12 pm, ksun kavi.sunda...@gmail.com wrote: Welcome to JQuery. Try this script $(document).ready(function() { $('#time').click(function(){ if($('input[type=checkbox]').attr('checked')) $('#showtime').show(); else $('#showtime').hide(); } ) }); /script /head body a href=# id=timeINPUT TYPE=checkbox NAME=limit VALUE=y/ aIset report period/I div id=showtime [] /div On Dec 11, 2:21 pm, frits1607 v...@vulkor.net wrote: On Dec 11, 6:47 pm, Paul Mills paul.f.mi...@gmail.com wrote: Hi, This selector looks a bit strange $('a#period'). Can you post the relevant HTML code please. Paul Paul, It looks like this: a href=# id=timeINPUT TYPE=checkbox NAME=limit VALUE=y/ aIset report period/I div id=showtime [] /div It looks a bit funny, but I do not know what is wrong.- Hide quoted text - - Show quoted text -
[jQuery] Re: ask : jquery validation plugins not working
Ok, I think I found the problem you form input elements don't have unique names (check how many times you have 'expPerson1' 'expPerson2' etc). so the validation plugin only picks the first ones. give unique names and then try. The following is the code in validate.jquery.js file that does this , look at the comment // select only the first element for each name, and only those with rules specified. Hope this helps. elements: function() { var validator = this, rulesCache = {}; // select all valid inputs inside the form (no submit or reset buttons) // workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved return $([]).add(this.currentForm.elements) .filter(:input) .not(:submit, :reset, :image, [disabled]) .not( this.settings.ignore ) .filter(function() { !this.name validator.settings.debug window.console console.error( %o has no name assigned, this); // select only the first element for each name, and only those with rules specified if ( this.name in rulesCache || !validator.objectLength($ (this).rules()) ) return false; rulesCache[this.name] = true; return true; }); }, On Dec 3, 12:00 am, Adwin Wijaya [EMAIL PROTECTED] wrote: Here is the test pagehttp://wysmedia.com/test/ you can delete the first field .. and the validate() will work .. but when you delete the second, third, etc ... the validation will simply said it is valid and allow me to go to next page. On Dec 2, 5:16 pm, Jörn Zaefferer [EMAIL PROTECTED] wrote: Could you provide a testpage? Jörn On Mon, Dec 1, 2008 at 10:32 PM,AdwinWijaya [EMAIL PROTECTED] wrote: Hi jquery users, I have forms which has a lot of input inside and all of it I set as required. Actually I generated the form using database, not by hand :) each input has unique id (generated by server). at the moment, the validation wont work on all field, it just detect the first fields ... (eg: houseHoldExpfood, expPerson1food, expPerson2food) .. but ignored another fields. is this jquery validation bug ? here is My javascript code: $(document).ready(function(){ $('#householdBudgetForm').validate({ errorLabelContainer: $('#householdBudgetErrorMsg'), submitHandler: submitHouseholdBudgetForm }); }); here is my form : form action=/save method=post name=BudgetForm id=BudgetForm table width=100% thead tr thExpenses/th thSuggested exp/th thHousehold exp/th th%/th thPerson1/th thPerson2/th thReason/th /tr /thead tbodytr class=tr_even tdFood incl groceries take aways/td td 2,100 input type=hidden value=2100.00 id=suggestedExpfood name=suggestedExp/ /td tdinput type=text title=Please enter Expense for Food incl groceries amp; take aways myid=food value= id=houseHoldExpfood name=houseHoldExp size=10 class=money required houseHoldExp//td td span id=percentagefood/ /td td input type=text title=Please enter Expense Person 1 for Food incl groceries amp; take aways myid=food value= id=expPerson1food name=expPerson1 size=10 class=money required expPerson1/ /td td input type=text title=Please enter Expense Person 1 for Food incl groceries amp; take aways myid=food value= id=expPerson2food name=expPerson2 size=10 class=money required expPerson2/ /td td span style=margin: 0pt; padding: 0pt; class=reason id=reasonfood input type=hidden value= id=reasonfood name=reason/ a class=reasonLink myid=food id=reasonLinkfood href=#img src=/ilink/images/reason.png//a /span /td /tr tr class=tr_odd tdPhone mobile internet/td td 830 input type=hidden value=830.00 id=suggestedExpcommunication name=suggestedExp/ /td tdinput type=text title=Please enter Expense for Phone mobile internet myid=communication value= id=houseHoldExpcommunication name=houseHoldExp size=10 class=money required houseHoldExp//td td
[jQuery] Re: clearcase error when trying to add jquery-1.2.6.min.js to source control
a little update on this. I still haven't figured out how to resolve the issue, but for now, someone pointed out to me that clearcase has problems with very long lines (more than 8000 characters). I am trying to use cleartool to specify the file type while adding the file. Will update once I get that working. On Dec 1, 2:45 pm, ksun [EMAIL PROTECTED] wrote: Today I tried adding jquery-1.2.6.min.js to source control (Rational ClrearCase). below is the error I got. I didn't get the error when I tried jquery-1.2.6.js. Anyone know why the minified version gives the error. I would like to use the minified version for the obvious reasons. I found some topics when googling this error about using binary type for the file. My understanding is that the minified file is a text file, I don't have any problem opening in DreamWeaver (it is definitely text) , Is clearcase thinking it is not a text file? Error Message : Type manager text_file_delta failed create_version operation. PS: I would rather not use Clearcase, but I am stuck with it at my current workplace. Thanks ksun
[jQuery] Re: ask : jquery validation plugins not working
I have never used validation plugin before so excuse me if I'm wrong. But just looking at your code I don't see any element with householdBudgetForm id in your code (on which you are calling validate), the form id is BudgetForm On Dec 2, 5:16 am, Jörn Zaefferer [EMAIL PROTECTED] wrote: Could you provide a testpage? Jörn On Mon, Dec 1, 2008 at 10:32 PM, Adwin Wijaya [EMAIL PROTECTED] wrote: Hi jquery users, I have forms which has a lot of input inside and all of it I set as required. Actually I generated the form using database, not by hand :) each input has unique id (generated by server). at the moment, the validation wont work on all field, it just detect the first fields ... (eg: houseHoldExpfood, expPerson1food, expPerson2food) .. but ignored another fields. is this jquery validation bug ? here is My javascript code: $(document).ready(function(){ $('#householdBudgetForm').validate({ errorLabelContainer: $('#householdBudgetErrorMsg'), submitHandler: submitHouseholdBudgetForm }); }); here is my form : form action=/save method=post name=BudgetForm id=BudgetForm table width=100% thead tr thExpenses/th thSuggested exp/th thHousehold exp/th th%/th thPerson1/th thPerson2/th thReason/th /tr /thead tbodytr class=tr_even tdFood incl groceries take aways/td td 2,100 input type=hidden value=2100.00 id=suggestedExpfood name=suggestedExp/ /td tdinput type=text title=Please enter Expense for Food incl groceries amp; take aways myid=food value= id=houseHoldExpfood name=houseHoldExp size=10 class=money required houseHoldExp//td td span id=percentagefood/ /td td input type=text title=Please enter Expense Person 1 for Food incl groceries amp; take aways myid=food value= id=expPerson1food name=expPerson1 size=10 class=money required expPerson1/ /td td input type=text title=Please enter Expense Person 1 for Food incl groceries amp; take aways myid=food value= id=expPerson2food name=expPerson2 size=10 class=money required expPerson2/ /td td span style=margin: 0pt; padding: 0pt; class=reason id=reasonfood input type=hidden value= id=reasonfood name=reason/ a class=reasonLink myid=food id=reasonLinkfood href=#img src=/ilink/images/reason.png//a /span /td /tr tr class=tr_odd tdPhone mobile internet/td td 830 input type=hidden value=830.00 id=suggestedExpcommunication name=suggestedExp/ /td tdinput type=text title=Please enter Expense for Phone mobile internet myid=communication value= id=houseHoldExpcommunication name=houseHoldExp size=10 class=money required houseHoldExp//td td span id=percentagecommunication/ /td td input type=text title=Please enter Expense Person 1 for Phone mobile internet myid=communication value= id=expPerson1communication name=expPerson1 size=10 class=money required expPerson1/ /td td input type=text title=Please enter Expense Person 1 for Phone mobile internet myid=communication value= id=expPerson2communication name=expPerson2 size=10 class=money required expPerson2/ /td td span style=margin: 0pt; padding: 0pt; class=reason id=reasoncommunication input type=hidden value= id=reasoncommunication name=reason/ a class=reasonLink myid=communication id=reasonLinkcommunication href=#img src=/ilink/images/ reason.png//a /span /td /tr tr class=tr_even tdEntertainment, pay tv/td td 1,100 input type=hidden value=1100.00 id=suggestedExpentertainment name=suggestedExp/ /td tdinput type=text title=Please enter Expense for Entertainment, pay tv myid=entertainment value= id=houseHoldExpentertainment name=houseHoldExp size=10 class=money required houseHoldExp//td td span id=percentageentertainment/ /td td input type=text title=Please enter Expense Person 1 for Entertainment, pay tv myid=entertainment value= id=expPerson1entertainment name=expPerson1 size=10 class=money required expPerson1/ /td td input type=text title=Please enter Expense
[jQuery] clearcase error when trying to add jquery-1.2.6.min.js to source control
Today I tried adding jquery-1.2.6.min.js to source control (Rational ClrearCase). below is the error I got. I didn't get the error when I tried jquery-1.2.6.js. Anyone know why the minified version gives the error. I would like to use the minified version for the obvious reasons. I found some topics when googling this error about using binary type for the file. My understanding is that the minified file is a text file, I don't have any problem opening in DreamWeaver (it is definitely text) , Is clearcase thinking it is not a text file? Error Message : Type manager text_file_delta failed create_version operation. PS: I would rather not use Clearcase, but I am stuck with it at my current workplace. Thanks ksun