[jQuery] Re: Way to convert DOM event to jQuery event?
Do you really need to output this data embedded in the HTML? Does it have any meaning/purpose without Javascript? There are two simple non- hackish ways you can do it: 1: load data later via XHR, use an element identifier to bind it 2: output metadata in the class attribute - it's valid, and not against the specification - the class attribute is not specifically meant for presentation, the specs say For general purpose processing by user agents. ex: class=link { foo: 'bar', amp: 'bamp', x: [1,2,3] }. It's easy to create your own parser for that: $.fn.mdata = function(){ return window[eval](( + this[0].className.match(/{.*}/) + )); }; $('a').mdata() == Object foo:'bar' etc.. It will work as long as you use valid JSON. cheers, Ricardo On Sep 22, 8:41 pm, WalterGR walte...@gmail.com wrote: On Sep 22, 4:35 pm, Ricardo ricardob...@gmail.com wrote: This doesn't make any sense. If you're already using jQuery why keep your handler in the HTML? Because I need to pass additional information to the event handler in a clean way. (i.e. rather than hacks using various attributes on the anchor.) Is there a non-hackish way to do this? Thanks for the code snippet - that's what I was looking for. Walter
[jQuery] Plugin development - how to access the current object from a sub-method?
Supposing I have this: jQuery.fn.myPlugin = function(){ // }; jQuery.fn.myPlugin.myMethod = function(){ // ? }; $('#test').myPlugin.myMethod(); How can I access the current object or element collection from inside jQuery.fn.myPlugin.myMethod? Is it possible at all? thanks, - ricardo
[jQuery] Re: Creating callable methods, and binding them to objects' actions.
I don't think you need the colon in there (nor the single quotes) $(input[name=donation_type]) On Feb 19, 4:04 am, mkmanning michaell...@gmail.com wrote: You shouldn't have to refer to the same object in different ways, $ (input:[name='donation_type']) will work for both getting the value and binding an event. The @ before the attribute name was deprecated as of version 1.2 On Feb 18, 9:51 pm, gberz3 gbe...@gmail.com wrote: Ok, I got it to work using the following: $(#chargetotal).change(updateDonationTotal); $(input:[name='donation_type']).change(updateDonationTotal); I mistakenly posted chargetotal as the radio when it was actually a text field. That said, what is the difference between the following items: var donation_type = $(input:[...@name:donation_type]:checked).val(); $(input:[name='donation_type']).change(updateDonationTotal); It doesn't seem very intuitive to have to refer to the same item in different ways in order to get different results. I should be able to say GET OBJECT where NAME EQUALS regardless of whether I'm looking for its value or to bind to one of its methods. Can someone shed some light on why I must call each of these methods on the input in the different manners? Thanks. On Feb 18, 7:10 pm, mkmanning michaell...@gmail.com wrote: try: $(input:[...@id:chargetotal]).change(updateDonationTotal); On Feb 18, 1:55 pm, gberz3 gbe...@gmail.com wrote: Hi All, I'm having a bit of a problem with selectors and binding in jQuery. Basically I want to do 2 things: 1) create a javascript method callable by name that updates a div 2) bind that method to a set of radio buttons that runs the method on change It seems that none of the examples explicitly cover instances where you roll your own methods. They all assume function(){} which I personally consider messy. That said, I have the following code thus far: script type=text/javascript $(document).ready(function(){ function updateDonationTotal(){ var amount = $('#chargetotal').val(); var multiplier = 0; var total = 0; var donation_type = $(input:[...@name:donation_type]:checked).val (); var message = ; //it's gonna be one of: donation_general, donation_stop_tab, donation_pipe switch(donation_type){ case 'donation_general': {multiplier = 1; break} case 'donation_stop_tab': {multiplier = 500; break} case 'donation_pipe': {multiplier = 100; break} } total = amount * multiplier; message = nbsp; x + multiplier + = + total; $(#donation_total).html(message); console.log(message); }; $(input:[...@id:chargetotal]).change(updateDonationTotal();); }); /script The method 'updateDonationTotal' works fine. However, I receive errors when trying to bind the method in various ways to the radio buttons. I've tried 'bind', 'click', 'change'...all error out. Please advise. Best!
[jQuery] Re: Creating callable methods, and binding them to objects' actions.
I meant to say they are not required (when the value has no special characters). cheers, - ricardo On Feb 19, 1:02 pm, mkmanning michaell...@gmail.com wrote: Missed the colon, the single quotes should be OK; the jQuery docs' example even uses them: $(input[name='newsletter']) On Feb 19, 12:11 am, Ricardo Tomasi ricardob...@gmail.com wrote: I don't think you need the colon in there (nor the single quotes) $(input[name=donation_type]) On Feb 19, 4:04 am, mkmanning michaell...@gmail.com wrote: You shouldn't have to refer to the same object in different ways, $ (input:[name='donation_type']) will work for both getting the value and binding an event. The @ before the attribute name was deprecated as of version 1.2 On Feb 18, 9:51 pm, gberz3 gbe...@gmail.com wrote: Ok, I got it to work using the following: $(#chargetotal).change(updateDonationTotal); $(input:[name='donation_type']).change(updateDonationTotal); I mistakenly posted chargetotal as the radio when it was actually a text field. That said, what is the difference between the following items: var donation_type = $(input:[...@name:donation_type]:checked).val(); $(input:[name='donation_type']).change(updateDonationTotal); It doesn't seem very intuitive to have to refer to the same item in different ways in order to get different results. I should be able to say GET OBJECT where NAME EQUALS regardless of whether I'm looking for its value or to bind to one of its methods. Can someone shed some light on why I must call each of these methods on the input in the different manners? Thanks. On Feb 18, 7:10 pm, mkmanning michaell...@gmail.com wrote: try: $(input:[...@id:chargetotal]).change(updateDonationTotal); On Feb 18, 1:55 pm, gberz3 gbe...@gmail.com wrote: Hi All, I'm having a bit of a problem with selectors and binding in jQuery. Basically I want to do 2 things: 1) create a javascript method callable by name that updates a div 2) bind that method to a set of radio buttons that runs the method on change It seems that none of the examples explicitly cover instances where you roll your own methods. They all assume function(){} which I personally consider messy. That said, I have the following code thus far: script type=text/javascript $(document).ready(function(){ function updateDonationTotal(){ var amount = $('#chargetotal').val(); var multiplier = 0; var total = 0; var donation_type = $(input:[...@name:donation_type]:checked).val (); var message = ; //it's gonna be one of: donation_general, donation_stop_tab, donation_pipe switch(donation_type){ case 'donation_general': {multiplier = 1; break} case 'donation_stop_tab': {multiplier = 500; break} case 'donation_pipe': {multiplier = 100; break} } total = amount * multiplier; message = nbsp; x + multiplier + = + total; $(#donation_total).html(message); console.log(message); }; $(input:[...@id:chargetotal]).change(updateDonationTotal();); }); /script The method 'updateDonationTotal' works fine. However, I receive errors when trying to bind the method in various ways to the radio buttons. I've tried 'bind', 'click', 'change'...all error out. Please advise. Best!
[jQuery] Re: How to surround All content after a specified HTML attribute H2?
You can't insert invalid HTML into the DOM. Use the nextUntil plugin by John Resig (I'm starting to think this belongs in the core): $.fn.nextUntil = function(expr) { var match = []; this.each(function(){ for( var i = this.nextSibling; i; i = i.nextSibling ) { if ( i.nodeType != 1 ) continue; if ( jQuery.filter( expr, [i] ).length ) break; match.push( i ); } }); return this.pushStack( match, arguments ); }; then you can do this: $('h2').each(function(){ $(this).nextUntil('h2').wrapAll('div class=contents /'); }); cheers, - ricardo On Feb 19, 8:21 pm, Charlie Griefer charlie.grie...@gmail.com wrote: No answer yet. I've tried playing around with using:$('h2').after('div class=someclass'); $('h2:not(:first)').before('/div'); but that doesn't seem to be working (and is also problematic because it leaves an open div after the last h2). it seems that the after() and before() methods each want to insert a full element (opened and closed). i can't tell, but i get the impression that jQuery is closing the div class=someclass div automatically. hoping somebody else might jump in with a more elegant (and correct/working) solution. On Thu, Feb 19, 2009 at 3:17 PM, cchun...@gmail.com cchun...@gmail.comwrote: Ok i have tried $('.tabs h2').next().wrapAll('div class=tabbody/div'); but it does not want to wrap all the paragraphs/tables/html in the one div. Any ideas? Thanks for the help! On Feb 19, 12:21 pm, Charlie Griefer charlie.grie...@gmail.com wrote: actually i should clarify... not change, but wrap the elements following h2 elements with the specified HTML. On Thu, Feb 19, 2009 at 10:00 AM, Charlie Griefer charlie.grie...@gmail.com wrote: On Thu, Feb 19, 2009 at 9:27 AM, cchun...@gmail.com cchun...@gmail.comwrote: I am trying to look through content in a div and if i find an H2 or whatever attribute the content or HTML that follows it will be encloded in a div with a class. I will do this for every H2 so if i have 3 H2's and some paragraphs after them it will surround all HTML after each of the H2 in a div. This will change the element following all h2 elements in the doc. script $(function() { $('h2').next().wrap('div class=someclass/div'); }); /script If you want it to be just within a certain div, and assuming that div has an id attribute of foo, it would be: script $(function() { $('#foo h2').next().wrap('div class=someclass/div'); }); /script -- 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. -- 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.- Hide quoted text - - Show quoted text - -- 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: Using jQuery.noConflict() with Prototype/Scriptaculous
I find it more practical to use an anonymous function as in (function ($){..}(jQuery) and keep the '$' reference, or do all the work at once to avoid confusion: (function($){ $(...) })( jQuery.noConflict() ) or jQuery.noConflict()(function($){ $(...) }); On Jan 7, 4:55 am, seasoup seas...@gmail.com wrote: noConflict was designed specifically with prototype in mind :) The easiest way to do both jQuery and proto is to do: var $j = jQuery.noConflict(); and use $j instead of $ for jQuery. $j('#id'), for example. On Jan 6, 10:23 pm, Magnificent imightbewrongbutidontthin...@gmail.com wrote: Hi Erik, thanks for the reply. I've been messing with things and I tried replacing my calls to local versions of prototype/scriptaculous to use google: script src=http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/ prototype.js type=text/javascript/script script src=http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.2/ scriptaculous.js type=text/javascript/script And it seems to be working now. Does anyone know if there's a known issue using jquery's noConflict() with prototype/scriptaculous? I'm wondering if the (older) local version I was using was the culprit. It looks like it.
[jQuery] Re: insert div into group ordered by ID..
I've since updated the script by request, it failed if you began with a single element in the container. It now sorts by any attribute you want (ids by default) and works with multiple elements both ways. http://ff6600.org/j/jquery.insertInOrder.js Examples at: http://jsbin.com/itofi http://jsbin.com/itofi/edit (source) cheers, - ricardo On 22 dez 2008, 15:54, Tbone 95dak...@gmail.com wrote: Thanks to you, too, ksunBetween you and Ricardo, I think I understand this now! On Dec 22, 11:42 am, ksun kavi.sunda...@gmail.com wrote: //locate thedivbefore which you want toinsertand theninsert, assuming they are ordered alphabetically $('div[id]').each(function(){ if ($(this).attr('id') 'delta') $(this).before('divid=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 yourinsertto 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 willinsertgamma1 before epsilon. $('#gamma~#epsilon').before('divid=gamma1/'); I first used after(), but that didn't work, looks like $ ('#gamma~#epsilon') selects #epsilon.- Hide quoted text - - Show quoted text -
[jQuery] Re: default value of an object's property
or simply if (!Obj.sortby) Obj.sortby = 'time'; it's a bit more efficient. All of undefined, null, 0 or will evaluate to false, there's no need to check for each of them. Anyway, Alexandre, the ternary you posted should also work, there is probably something else wrong in your code. - ricardo On Feb 18, 3:52 pm, Josh Nathanson joshnathan...@gmail.com wrote: I think this might work, give it a try: Obj.sortby = Obj.sortby || 'time'; -- Josh -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Alexandre Plennevaux Sent: Wednesday, February 18, 2009 9:07 AM To: Jquery-en Subject: [jQuery] default value of an object's property hi there, a quick question: i'm using an object to pass a series of variables. Sometimes, i test for a specific property, which might not exist. I can't seem to find the right way, i tried Obj.sortby = (typeof Obj.sortby == 'undefined' || Obj.sortby=='' ||Obj.sortby == null) ? 'time' : Obj.sortby; but everytime that property sortby hasn't been set, firebug returns it as null can you clear that up for me? Thanks a lot! Alexandre
[jQuery] Re: $.getScript fatal error with XML.
getScript is, as it's name says, for getting scripts. What happens when you use the code below? $.get(getURL, function(xml){ alert(xml); }); On Feb 17, 3:33 am, Kuma Pageworks brian.overl...@gmail.com wrote: I posted about this before, but the response didn't help - so I thought I'd try posting again. I have a function that's putting together a GET request and sending it off with $.getScript to retrieve an XML file. When I get the response back, Javascript throws an exception: missing ; before statement. I take that to mean that jQuery is handling the XML like a Javascript file. But the response is there! I can't get this to work with $.get - it just hasn't worked. So what I'm wondering is if I can work around this exception, or find some other way to get at the response. Here's my code: if(hasError == false) { $('#login').hide('slow'); var getURL = http://***.com/app/xml.pl?Email=; + emailVal + Password= + passVal; try { $.getScript(getURL, function(xml){ getXML(xml); }); } catch (e){ console.log(e); } } If someone can explain how I can get $.get to work, I'd take that as a positive step, too.
[jQuery] Re: $.getScript fatal error with XML.
AJAX doesn't work cross-domain, doesn't matter what function you are using. You have to either use JSONP (http://remysharp.com/2007/10/08/ what-is-jsonp/) or a proxy on your server. On Feb 17, 12:48 pm, Kuma Pageworks brian.overl...@gmail.com wrote: I get the 'restricted URI' error - since the URL is on a remote server, $.get isn't working. I may have to use $.ajax. On Feb 17, 2:01 am, Ricardo Tomasi ricardob...@gmail.com wrote: getScript is, as it's name says, for getting scripts. What happens when you use the code below? $.get(getURL, function(xml){ alert(xml); }); On Feb 17, 3:33 am, Kuma Pageworks brian.overl...@gmail.com wrote: I posted about this before, but the response didn't help - so I thought I'd try posting again. I have a function that's putting together a GET request and sending it off with $.getScript to retrieve an XML file. When I get the response back, Javascript throws an exception: missing ; before statement. I take that to mean that jQuery is handling the XML like a Javascript file. But the response is there! I can't get this to work with $.get - it just hasn't worked. So what I'm wondering is if I can work around this exception, or find some other way to get at the response. Here's my code: if(hasError == false) { $('#login').hide('slow'); var getURL = http://***.com/app/xml.pl?Email=; + emailVal + Password= + passVal; try { $.getScript(getURL, function(xml){ getXML(xml); }); } catch (e){ console.log(e); } } If someone can explain how I can get $.get to work, I'd take that as a positive step, too.
[jQuery] Re: element selection
Probably $('#'+id).remove(). It's an usual string. On Feb 17, 3:56 pm, Ashit Vora a.k.v...@gmail.com wrote: Hi, I 've a small query, I have a table with each row having a unique id (eg. 1,2,3,4) As an Ajax response I receive ID in JSON format. I want to remove the row having that ID. For selecting element using Id, I generally use $('id').fadeOut(); but how do I out the value of variable in this ? (resp.id in my case) Thanks :)
[jQuery] Re: Exploding nested divs....
What do you mean by explode? remove? On Feb 17, 4:50 pm, webspee...@gmail.com webspee...@gmail.com wrote: Hey all. Exploding a simple div is easy enough, but can you explode nested divs? I have a div container and inside it I have content generated from an AJAX call. When I explode the outer div, I don't get the pieces and the screen freezes up for a second. I don't know if the div is too large or if it is because of the inside div. Also, I would assume the inside div (the one returned via AJAX) would have to be re-binded, is this correct? If so, how do you bind on an explode? I can't simply write the statement, otherwise it would explode immediately on the return from the AJAX call. I was just curious about this is all. ...
[jQuery] Re: Minified and Gzip?
How are you checking it? The 'Net' tab in Firebug should tell you if it's gzipped or not. On Feb 17, 10:00 pm, ScottChiefBaker scott.ba...@gmail.com wrote: How do I setup JQuery to be server Gzipped? Using apache I installed mod_deflate and set it up to serve .js files as gzipped, but it doesn't seem to be working. Does anyone have any example configurations I could steal from? - Scott
[jQuery] Re: Order Items. Please help me. Thank You.
That's because you have that empty li style=display:none/li. Is it really necessary? just decrement the index to start at 0: $('#Themes li').each(function(index){ index--; $('input:hidden', this).each(function(){ var fixName = $(this).attr('name').replace(/\[\d\]/, '['+index +']'); $(this).attr('name', fixName); }); }); cheers, - ricardo On Feb 17, 10:56 pm, shapper mdmo...@gmail.com wrote: I added an input which shows the number of items in the list ... The problem is that I am not able to reorder the list so it is 0 based ... Any idea? Thanks, Miguel On Feb 18, 1:48 am, shapper mdmo...@gmail.com wrote: I have been trying to make this work but no success ... ... in fact the inputs get undefined. I am not sure if I am using your function on the right way. The function should be called, I think, after adding or removing an item to reorder the ids. Anyway, I created an example:http://www.27lamps.com/Beta/List/List.html Please, not that you have to select a subject and at least one level to add it to the list. Could someone, please, help me out with this? Basically, every time I add or remove an item I need to reorder the names of the input fields. Please check my original message on this post. It explains the situation. Thanks, Miguel On Feb 12, 4:36 am, Ricardo Tomasi ricardob...@gmail.com wrote: Probably not the most efficient function, but should work: $('#ThemesList li').each(function(index){ $('input:hidden', this).each(function(){ var fixName = $(this).attr('name').replace(/\[\d\]/, '['+index +']'); $(this).attr('name', fixName); }); }); - ricardo On Feb 11, 7:19 pm, shapper mdmo...@gmail.com wrote: Hello, I am adding and removing a items from a list, using JQuery, which is rendered has follows: ol id=ThemesList li input type=hidden name=Themes[0].Subject value=A / input type=hidden name=Themes[0].Levels value=L1,L2 / input type=hidden name=Themes[0].Description value=Paper / /li li input type=hidden name=Themes[2].Subject value=B / input type=hidden name=Themes[2].Levels value=L1,L5 / /li li input type=hidden name=Themes[5].Subject value=D / input type=hidden name=Themes[5].Levels value=L2,L4 / input type=hidden name=Themes[5].Description value=Book / /li /ol Every time I add or remove a Theme I need to be sure that the list is ordered (name) starting with Themes[0]. So basically I need to loop through each list item in list ThemesList. - In first list item all HIDDEN inputs names should start with Themes [0] - In second list item all HIDDEN inputs names should start with Themes [1] ... So in this example, Themes[2]. ... would become Themes[1]. ... and Themes[5]. ... would become Themes[2]. ... Could someone please help me out? I have no idea how to do this. Thanks, Miguel
[jQuery] Re: selector best practice
Not going to native methods I'd say the fastest selector without an ID would be $(#tableid td.cellclass) as that will call getElementByID and getElementsByTagName/getElementsByClassName from the #tableid context (or querySelectorAll). Anyway, you only need to add more selectors if you want to enforce the relationships, the more of them the slower it gets. For IDs you should always use just the element's ID. Anything that comes before it will consume parsing time needlessly if the ancestors are not important. - ricardo On Feb 16, 4:30 am, SteelRing steelr...@gmail.com wrote: This may sound stupid to y'all jquery practitioners, but i wonder which method is fastest (recommended) for selecting a cell with a class in a big table (think like 1000+ rows 100+ columns): (#tableid tbody tr.rowclass td.cellclass) or is it (td.cellclass) or (.cellclass). And how about if the cell happens to have a unique id: (#tableid tbody tr#uniquerow td#uniqueid) or just (#uniqueid) Philosophically, the question being is it better to put as much detail as structurally already known by the programmer into the selector or just anything goes and let jquery handle it as long as it works.
[jQuery] Re: Permission denied to get property HTMLDivElement.parentNode
Some live samples would be very useful. You probably mean jQuery 1.3.1 right? On Feb 16, 11:58 am, David garcia.narb...@gmail.com wrote: Usually I also get that error, Permission denied to get property HTMLDivElement.parentNode, just loading HTML with a few jquery lines of code. I have to refresh the web page (F5) to get it disappear. I use jQuery 1.1 and jQueryUI 1.6rc6 On 10 feb, 22:45, Justin jgal...@gmail.com wrote: I've seen various number of posts related to the same issue and some folks think that it's a Mozilla bug (https://bugzilla.mozilla.org/ show_bug.cgi?id=208427) but I'm questioning whether it's really a jQuery bug that should be addressed by re-evaluating 'withinElement' where the problem currently seems to manifest rather than waiting for the Mozilla folks to fix it. FF is after all a very popular browser and this seems to be an easy bug that will very surface quickly. Another search I did yielded some results about people discussing this error due to cross-site scripting exploits and you can not use your web site to access the objects on a different web site. In my case, I'm fairly certain (99%) that my own code isn't loading any script files from other sites so this may not be the problem. I used to have a page that used YUI tabs and within the tab, a table for data display and a form. No matter how many times I hovered and mouse in/out in the input fields, I never saw this error. I then switched over to jQuery tabs along with Flexigrid in lieu of the tab and right away, I'm seeing this error on the same form that did not have this problem earlier. The problem seems to be that element that receives the event (event.relatedTarget) is of class type, 'anonymous-div' and somehow, it's not a node owned by the document from the current site, although I do not know how. I've also changed my form from div to table (some folks in one of the other posts mentioned this) and it had no effect on this bug. Justin
[jQuery] Re: how to zebra stripe divs?
The code in your test page still reads $(div:.postSummary (odd)).addClass(odd), not $(div.postSummary:odd).addClass(odd); On Feb 17, 12:04 am, mark law m...@digiflip.tv wrote: Thanks MorningZ :), yes that is the one I'm trying to mimic. odd is only declared in: $(div.postSummary-teaser:odd).addClass(odd); Where else should it be? I was hoping this code would just add it to alternate divs with a class of postSummary-teaser The html is actually: !-- Entry -- div class=postSummary id=post-125 !-- Post Top Summary -- div class=postSummary-top h3a href=linktitle/a/h3 pPosted by: a href=link title=View all posts by class=author-linkauthor name/a in ilabel here/inbsp; on span class=post-datedate here/span /p /div !-- Post Teaser Text -- div class=postSummary-teaser html of teaser text goes here !-- Post Footer -- p class=postSummary-footer a href=link class=postSummary-commentslink to comments/a a href=link to full article class=postSummary-readmoreRead More.../a /p /div !-- Post Divider -- hr class=postEntry-divider / /div div class=clear/div then it repeats itself if there are more posts. I now realise I should be using postSummery not postSummary-teaser, I made the change. I just tried it in a static page with nothing else in it just to make sure there are no conflicts. It still does not work though:http://www.digiflipconcepts.com/digiflip-v3/templates/digiflip/test.html :( ? 2009/2/17 MorningZ morni...@gmail.com so this is the jQuery you are trying to mimic? $(tr:nth-child(odd)).addClass(odd); ?? that uses current selector syntax (http://docs.jquery.com/Selectors/ nthChild#index http://docs.jquery.com/Selectors/%0AnthChild#index), and would indeed work on table tr tdRow 1/td /tr tr tdRow 2/td /tr tr tdRow 3/td /tr tr tdRow 4/td /tr /table If you had div class=postSummary-teaserTeaser 1/div div class=postSummary-teaserTeaser 2/div div class=postSummary-teaserTeaser 3/div div class=postSummary-teaserTeaser 4/div div class=postSummary-teaserTeaser 5/div then, there's no reason why $(div.postSummary-teaser:odd).addClass(odd); wouldn't give zebra stripes (as long as class name odd is declared somewhere) On Feb 16, 9:09 pm, mark law m...@digiflip.tv wrote: I copied it from here: http://blog.jquery.com/2006/10/18/zebra-table-showdown/andtried unsuccessfully to modify it for div classes ... 2009/2/17 MorningZ morni...@gmail.com I'm just curious... where are you getting your syntax from? div:.postSummary .postSummary-teaser(odd) ?? there's now where in the documentation (http://docs.jquery.com) where that syntax is shown On Feb 16, 6:31 pm, morktron m...@digiflip.tv wrote: Hi I'm just wondering whether it is possible to zebra stripe alternate divs with the same class name? The class name is .postSummary-teaser, I tried this: script type=text/javascript window.onload = function(){ $(div:.postSummary-teaser(odd)).addClass(odd);}; /script but no joy. I'm no Javascript programmer but it was easy to stripe alternate rows with a tutorial on the jQuerey site. There seems to be nothing about using divs? The page in question is in development here: http://www.digiflipconcepts.com/digiflip-v3/Rant-and-Rave Can anyone help? thanks -- View this message in context: http://www.nabble.com/how-to-zebra-stripe-divs--tp22048135s27240p2204. .. Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: getting ul html on each and appending to div problem
$(ul).each(function() { var ulla = jQuery(this).html(); //ulla is a 'private' variable here, it's only available inside this function. that's why it's undefined. }); This should work: jQuery(function($){ var items = $('#la ul').remove().find('li'); $(#la dl).empty().append( items ); }); By the way, I'm pretty sure having an unordered list directly inside a dl is invalid mark-up. - ricardo On Feb 17, 1:30 am, Mathew msin...@gmail.com wrote: im trying to look into a div and find each instance of a ul in that div and get all the li elements into a variable then remove the ul's and append the new ul with li from variable. here is what i have so far: Code: //var ulla = ' '; jQuery(ul).each(function() { var ulla = jQuery(this).html();}); jQuery(#la dl).remove(); jQuery(#la).append(dlul + ulla + /ul/dl); the structure is like: dl ul li li li li /ul ul li li /ul /dl im trying to get all of the li elements from all ul elements and store them so I can remove all the multiple ul elements and make one ul and put all the li elements inside this new single ul. I keep trying variations of this with different selectors and forms of each and i cant get anything into that ulla variable, i get undefined when loading the page for ulla with code above. can anybody see what i am doing wrong
[jQuery] Re: Feature Detection Best Practice?
I thought that was the point of $.support - If it doesn't support the standard implementation, then it's false. On Feb 14, 8:46 pm, Klaus Hartl klaus.ha...@googlemail.com wrote: On 14 Feb., 20:31, Chris cpot...@siolon.com wrote: On Feb 13, 2:34 am, Klaus Hartl klaus.ha...@googlemail.com wrote: That will not avoid IE's ClearType issue, since IE is supporting opacity and you still end up in the else branch. I think it's one of he rare cases where you need to do browser sniffing. I don't think there's a way to find out, if the ClearType issue is happening or not. It doesn't go in the else branch for IE 6/7 actually. It works as I intend. IE 8 however does go in the else branch. Interesting. I assumed $.support.opacity would be true in IE since it does support it, even though not as standard CSS3 property. --Klaus
[jQuery] Re: strange loop with livequery click
The point of livequery is you don't need to reattach the listeners everytime you add new elements. This line: $(li.reItem).livequery('click', function(event){ should be ran only once on $().ready(), not everytime you call loadForecast(). You're basically adding a new 'click' listener everytime you call the function, and it doesn't override the previous one. cheers, - ricardo On Feb 14, 11:26 pm, pedalpete p...@hearwhere.com wrote: I've got a page that I'm loading via ajax, and the first time I load the page, the click function works great. If I make a second ajax request and load new data, the clicks are triggering the function twice. Even though I empty the div before loading the new data, and then call livequery on the click. Any idea why livequery would do this, and what the solution would be? [code] function loadForecast(lat, long){ $('div#holdForecast').empty(); var i=1; $.ajax({ type: GET, url: widgets.php, data: lat=+lat+long=+long, success: function(response){ $('div#holdForecast').html('ul class=List'+response+'/ ul'); }); $(li.reItem).livequery('click', function(event){ alert(i); i++;} [/code] when I run this code, the alert shows (1) if i've only run the loadForecast function once. but if I get a second loadForecast function, then the alert shows the number of times I've called the funciton (2 or more). So that is how I'm figuring that the 'click' function is being called more than once per click. Other alerts further down in the code also get called multiple times as a result of the click.
[jQuery] Re: anyone tried alternatives to setting wmode on objects (lightbox on top issue)?
If I recall correctly you can stack an iframe of your own over the whole page (behind the lightbox) that will stay on top of everything. In the last project I needed to work around this, I just set visibility:hidden for all flash/iframe objects in the page when firing a lightbox. Not very noticeable and has no effect on usability. cheers, - ricardo On Feb 14, 12:38 pm, hedgomatic hedgoma...@gmail.com wrote: I'm working for an alt-weekly paper, and we have some animated flash ads that come from various sources, which aren't setting the WMode of their flash ads. further complicating things, our ad server backend is a shared platform, so I can't go modifying the script that generates the object tags. even /further/ complicating things, the ads display in an iframe on a different domain, so I can't modify the object tag after the fact (which adobe's stated doesn't work anyway, although I've seen otherwise?) I'm wondering if anyone's come up with alternative solutions, like embedding a swf in a parent div of a lightbox to force it on top of other flash objects, etc...I'd try it, but I don't have flash :] My first thought was to import whatever html was needed directly into a swf in the lightbox, but apparently flash only supports limited html (still?!?). Anyone have a novel solution for this? Even if it doesn't work across all browsers, if we can reduce the number of browsers it's a problem for, and get our advertisers to start publishing with the windowless option, it's better than where we're at now.
[jQuery] Re: Working with identical objects
That's quite a lot of code to read through in an email. Try reducing your code to the least necessary to exemplify your problem, then someone might take the time to help. From what I see: alert(jQ(option:selected, ModulesListObj).val()) This is catching all the selected options inside ModulesListObj, and that will be one option for every select you added. val() will then return the value only for the first element in that collection. That should probably be: alert(jQ(option:selected, this).val()) cheers, - ricardo On Feb 12, 11:53 pm, ShurikAg shuri...@gmail.com wrote: I don't believe that nobody have any suggestion...
[jQuery] Re: Working with identical objects
Sorry for the double messages. Actually that could simply be: alert( jQ(this).val() ) as val() called on a select will return the selected option's value. On Feb 15, 6:04 pm, Ricardo Tomasi ricardob...@gmail.com wrote: That's quite a lot of code to read through in an email. Try reducing your code to the least necessary to exemplify your problem, then someone might take the time to help. From what I see: alert(jQ(option:selected, ModulesListObj).val()) This is catching all the selected options inside ModulesListObj, and that will be one option for every select you added. val() will then return the value only for the first element in that collection. That should probably be: alert(jQ(option:selected, this).val()) cheers, - ricardo On Feb 12, 11:53 pm, ShurikAg shuri...@gmail.com wrote: I don't believe that nobody have any suggestion...
[jQuery] Re: Would some please tell me what's wrong with this syntax?
function getNewSchedule(response.MONTH, response.YEAR) { the parameteres when you declare a function are variable names, and those are invalid. Try function getNewSchedule(month, year) { and replace the response.XX references inside the function accordingly. You can then call the function passing those object properties: getNewSchedule(response.MONTH, response.YEAR) and access their values inside the function with the 'month' and 'year' variables. cheers, - ricardo On Feb 14, 1:19 am, Rick Faircloth r...@whitestonemedia.com wrote: Good call, James...couldn't see that one...I've been starting at it too long! How about another one? Here's the error message: missing ) after formal parameters function getNewSchedule(response.MONTH, response.YEAR) {\n And here's the code...ideas? Thanks! script function getNewSchedule(response.MONTH, response.YEAR) { var formval = { dsn: 'cfoutput#application.dsn#/cfoutput', month: response.MONTH, day: '01', year: response.YEAR }; console.log(formval); $.ajax ({ cache: false, type: post, url: ../components/floor_duty.cfc?method=get_new_schedulereturnFormat=json, dataType: json, data: formval, success: function(response) { if (response.MESSAGE == 'Success') { $('#li-none:visible').hide(); $('#schedule-month-year').empty().append('Below is the schedule for' + response.MONTH +' '+ response.YEAR); $('#schedule-instructions').fadeIn(500); $('#scheduleBody').fadeIn(500); populateDutyTable(response); } else { $('#li-below:visible').hide(); $('#none-date').empty().append(response.MONTH +' '+ response.YEAR); $('#li-none').fadeIn(500); $('#scheduleBody').fadeOut(250); } } }); } /script -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of James Sent: Friday, February 13, 2009 9:11 PM To: jQuery (English) Subject: [jQuery] Re: Would some please tell me what's wrong with this syntax? The word 'function' is not suppose to be there. It's there only when you define a function, not when you call it. On Feb 13, 4:07 pm, Rick Faircloth r...@whitestonemedia.com wrote: Hi, James, and thanks for the reply... I've got a page full of code and two other errors that are *seemingly* unrelated, however, anything is possible. Let me ask this in relation to the second error message: See anything wrong with this syntax (reponse section of an ajax function): success: function(response) { if (response.RESULT == 'Success') { $('#li-month-year-inst').fadeOut(250); $('#li-month-year').fadeOut(250); $('#li-new-schedule-message').empty().append('Here is the new schedule for '+ response.MONTH + response.YEAR).hide().fadeIn(500); function getNewSchedule(response.MONTH, response.YEAR); } else { $('#li-new-schedule-message').empty().append('An error occured. Please click the create link to try again.').hide().fadeIn(500); } } I'm getting this error message for the function getNewSchedule... line in the middle: missing ) after formal parameters function getNewSchedule(response.MONTH, response.YEAR);\n Ideas? Thanks, Rick -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of James Sent: Friday, February 13, 2009 8:50 PM To: jQuery (English) Subject: [jQuery] Re: Would some please tell me what's wrong with this syntax? I don't see the problem. Do you have more code than this somewhere that could be causing the error? On Feb 13, 3:16 pm, Rick Faircloth r...@whitestonemedia.com wrote: Thanks for the reply...the paren before the second function definitely shouldn't have been there... Now, with this: script $(document).ready(function() { $('.cancel').livequery('click', function() {
[jQuery] Re: Is there a way to make a textarea that auto expands as needed?
Did you skip my previous message? On Feb 12, 11:02 am, Rick Faircloth r...@whitestonemedia.com wrote: Ideas, anyone? -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Rick Faircloth Sent: Wednesday, February 11, 2009 6:56 PM To: jquery-en@googlegroups.com Subject: [jQuery] Is there a way to make a textarea that auto expands as needed? I'd like to figure out a way to make a textarea that expands with text input when necessary and shrinks, also, if possible...and without scrollbars. I've looked around, but haven't found a solution that does everything. Anyone know if that's possible with jQuery? Or how to do it? Rick
[jQuery] Re: Removing all styles from an element-
Even redeclaring all properties in CSS will be much better than using javascript to fix it. Something like #myModule * { margin:0; padding:0; font-family:Arial; color:#000; height:auto; width:auto; font-size:10px; letter-spacing:1; line-height: 1; text-indent:0; overflow:visible; border:0 none; background: #FFF; float:none; clear:none; } Should be enough, then you would just make sure you declare *every* style you need on on your own CSS, even the defaults. If you wanted complete outside styles 'protection', you could load everything inside an iframe. ? On Feb 12, 11:07 am, Nic Luciano adaptive...@gmail.com wrote: I considered it, but because of the ambiguity I run into I just need to specify every single Css property... Thought there might be something clever I could do with jquery but pobably not... Thanks Sent from my iPhone On Feb 12, 2009, at 12:08 AM, Ricardo Tomasi ricardob...@gmail.com wrote: You could a use kind of CSS reset for your container. I usually don't like '*' declarations but this seems fit here: #myModule * { margin:0; padding:0; font-family:Arial; color:#000; height:auto; width:auto } On Feb 11, 11:09 pm, Nic adaptive...@gmail.com wrote: The scenario: I am developing a module that will live on any page it's requested to live on (any website). The issue is that if the website it's on has a broad style definition (ie. p { margin: 20px; }), this will affect my elements (in addition to the styles I define). Is there a way I can ensure that only the styles I apply are used, or to clear all styles of my elements before I apply my own? So if someone has such a definition on their page, it won't effect my module. I know I could explicitly redefine the style myself, but there is no way of telling ahead of time what styles will be defined (without defining every single css property for every single element)- so a catch all would be nice. Thanks, Nichttp://www.twitter.com/nicluciano Sent from my iPhone
[jQuery] Re: Finding the last sibling.
If the input doesn`t exist nothing will be returned with nextAll. Same with jQuery Lover's approach. That's we need to get all the children: $('input').parent().children(':last') or alternatively $('input').siblings().andSelf().filter(':last-child') // I'd bet the other one is faster As Mike Manning pointed out, $(div :last-child) will return all the 'last-child's of all the descendants, not just the children. $(div :last-child) would be it. cheers, - ricardo On Feb 12, 4:19 am, mkmanning michaell...@gmail.com wrote: Somehow the selector disappeared :P $('input').nextAll(':last'); $(this).nextAll(':last'); On Feb 11, 10:17 pm, mkmanning michaell...@gmail.com wrote: $(div :last-child); finds all of the last-child elements, including descendant elements (e.g. if there were an a inside the span in your example it would be returned too). You can also not worry about the parent at all and just use the sibling selector: //or you could use :last-child As Ricardo suggested, you can use 'this' : $(this).nextAll(':last'); On Feb 11, 10:05 pm, Ricardo Tomasi ricardob...@gmail.com wrote: $(this).parent().children(':last') //or :last-child - assuming 'this' is the input element On Feb 12, 3:09 am, Risingfish risingf...@gmail.com wrote: Thanks Nic, How about if I'm using the input tag as the base? Can I do something like $(self:parent:last-child) ? On Feb 11, 8:13 pm, Nic Luciano adaptive...@gmail.com wrote: $(div :last-child); (or this wacky way I tried before I learned CSS selectors $(div).children()[$(div).children().size() - 1])...) Nic Lucianohttp://www.twitter.com/niclucianohttp://www.linkedin.com/in/nicluciano On Wed, Feb 11, 2009 at 9:49 PM, Risingfish risingf...@gmail.com wrote: Hi James, apologize for not being more precise. I'm using the input element as my base reference. So using that input element, I want to get the last sibling under the div. You are correct that if the span is not then the input is what I want. I may need to add more tags later (I'm sure you know hoe the development process goes when customers are involved. :) ), so a reliable way to get the last tag would be nice. Thanks! On Feb 11, 7:21 pm, James james.gp@gmail.com wrote: When you say last sibling in a parent, what does that mean? Which element is your base reference? In your example: div input .. / span.../span /div Do you mean your div is the base reference, and you want to find the last child (thus, span) relative to that? And if span is not there, you want input? On Feb 11, 4:12 pm, Risingfish risingf...@gmail.com wrote: Before I accidentally hit enter, this is what I was trying to type: :) div input .. / span.../span /div The span might or might not be there, so I would like to just get the last sibling in a parent. Thanks!
[jQuery] Re: New to JQuery, silly question.
I guess it's something else in your code that is going wrong. I just copied and pasted your JS and HTML and it works fine: http://jsbin.com/ibete http://jsbin.com/ibete/edit Can you post a test page like the one your working, showing this issue? Then I'm sure someone will spot the problem. cheers, - ricardo On Feb 12, 3:12 pm, Alexandru Dinulescu alex.d.a...@gmail.com wrote: Any info why the li:last and li.last do not work? the html was something like this ul liTest Test Test /li liTest Test Test /li li class=lastTest Test Test /li /ul so li.last and li:last equal the same thing Thanks for all the info so far --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile:http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf... MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php On Thu, Feb 12, 2009 at 6:38 PM, MorningZ morni...@gmail.com wrote: So all the parantheses are where they belong.. you should not use () in the document.ready line $(document).ready(blabla()) won't work $(document).ready(blabla) will work On Feb 12, 11:32 am, Alexandru Dinulescu alex.d.a...@gmail.com wrote: Also i didnt say this I said function blabla() { } $(document).ready(blabla()) ? So all the parantheses are where they belong... --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile: http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf... MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php On Thu, Feb 12, 2009 at 5:40 PM, MorningZ morni...@gmail.com wrote: For the first part of your post li:last gets the last li in the given ul li.last gets any li with the class of last For the second part of your post, your syntax is wrong $(document).ready(blabla) (note the lack of () after the function name) On Feb 12, 8:59 am, Alexandru Dinulescu alex.d.a...@gmail.com wrote: Why does this : $(document).ready(function(){ if($(.leftNav ul li:last).height() 32){ $(.leftNav ul li.last).addClass(lastWithItems); } }) work in 1.3.1 but not this $(document).ready(function(){ if($(.leftNav ul li.last).height() 32){ $(.leftNav ul li.last).addClass(lastWithItems); } }) (Notice the li.last on both lines) ??? Also why isnt it explained anywhere :( Another thing why cant i do this function blabla() { } $(document).ready(blabla()) ? and i have to do $(document).ready(function(){}) From what i recall i could do both things in 1.2.6, now with 1.3.1 those seem to be impossible, also why isnt there any mention on the Jquery doc/tutorial pages? :( Thanks --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML: http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile: http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf. .. MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php
[jQuery] Re: New to JQuery, silly question.
li:last and li.last are not the same element. li.last is the li class=last lastActive element, while li:last is giving you the *last* LI in the collection of *all* the LI's descending from .leftNav ul - that is the lia href=#HAX/a/ li element. Enforcing the child relationship should give you the expected results: $(.leftNav .menu ul li:last)[0] == $(.leftNav ul li.last)[0] cheers - ricardo On Feb 12, 4:56 pm, Alexandru Dinulescu alex.d.a...@gmail.com wrote: Here is the Link of the page in question. THIS WORKS:http://alexd.adore.ro/projects/threadsmith/getIdeas.html $(document).ready(function(){ if($(.leftNav ul li:last).height() 32){ $(.leftNav ul li.last).addClass(lastWithItems); } }) THIS DOESNT;http://alexd.adore.ro/projects/threadsmith/getIdeas2.html $(document).ready(function(){ if($(.leftNav ul li:last).height() 32){ $(.leftNav ul li:last).addClass(lastWithItems); } }) THIS DOESNT ALSOhttp://alexd.adore.ro/projects/threadsmith/getIdeas3.html $(document).ready(function(){ if($(.leftNav ul li.last).height() 32){ $(.leftNav ul li:last).addClass(lastWithItems); } }) --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile:http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf... MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php On Thu, Feb 12, 2009 at 7:15 PM, Liam Potter radioactiv...@gmail.comwrote: Hi Alexandru, I cannot see any reason why li.last would not work, as it would be no different then selecting any li with any class. Alexandru Dinulescu wrote: So this should work right? function blabla() { } $(document).ready(blabla); --- Any info why the li:last and li.last do not work? the html was something like this ul liTest Test Test /li liTest Test Test /li li class=lastTest Test Test /li /ul so li.last and li:last equal the same thing Thanks for all the info so far --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile: http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf... MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php On Thu, Feb 12, 2009 at 6:38 PM, MorningZ morni...@gmail.com mailto: morni...@gmail.com wrote: So all the parantheses are where they belong.. you should not use () in the document.ready line $(document).ready(blabla()) won't work $(document).ready(blabla) will work On Feb 12, 11:32 am, Alexandru Dinulescu alex.d.a...@gmail.com mailto:alex.d.a...@gmail.com wrote: Also i didnt say this I said function blabla() { } $(document).ready(blabla()) ? So all the parantheses are where they belong... --- Alexandru Dinulescu Web Developer (X)HTML/CSS Specialist Expert Guarantee Certified Developer XHTML:http://www.expertrating.com/transcript.asp?transcriptid=1879053 CSS :http://www.expertrating.com/transcript.asp?transcriptid=1870619 RentACoder Profile: http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInf... MainWebsite:http://alexd.adore.ro Portofolio:http://alexd.adore.ro/project_page.php On Thu, Feb 12, 2009 at 5:40 PM, MorningZ morni...@gmail.com mailto:morni...@gmail.com wrote: For the first part of your post li:last gets the last li in the given ul li.last gets any li with the class of last For the second part of your post, your syntax is wrong $(document).ready(blabla) (note the lack of () after the function name) On Feb 12, 8:59 am, Alexandru Dinulescu alex.d.a...@gmail.com mailto:alex.d.a...@gmail.com wrote: Why does this : $(document).ready(function(){ if($(.leftNav ul li:last).height() 32){ $(.leftNav ul li.last).addClass(lastWithItems); } }) work in 1.3.1 but not this $(document).ready(function(){ if($(.leftNav ul li.last).height() 32){ $(.leftNav ul li.last).addClass(lastWithItems); } }) (Notice the li.last on both lines) ??? Also why isnt it explained anywhere :( Another thing why cant i do this function blabla() { } $(document).ready(blabla()) ? and i have to do $(document).ready(function(){})
[jQuery] Re: how to fade in image after the site loads?
The 'load' event doesn't fire in Internet Explorer if the image is cached, maybe that's why. $('#photo img').bind('load readystatechange', function(e) { if (this.complete || this.readyState == 'complete' e.type = 'readystatechange') { $('.pic').fadeIn(); $('div.position').fadeOut(); $('.site').fadeIn(); }; }); On Feb 12, 3:32 pm, surreal5335 surrea...@hotmail.com wrote: Thanks a lot for the help, unfortunately it didnt take. One more thing, how could I go about getting the $('.site').fadeIn(); to execute after the other two have finished? I wish I could offer some suggestions to help spark an idea on your end, but I am drawing a complete blank...Which is why I am on here asking for help. So thank you very much for any other ideas you may have. On Feb 12, 3:54 am, Paul Mills paul.f.mi...@gmail.com wrote: Hi, Try something like this: $('#photo img').load(function() { $('.pic').fadeIn(); $('div.position').fadeOut(); $('.site').fadeIn(); }); The .load() event should fire when the images has loaded. You don't need to remove the classes pic and site to get the fades in/out to work. Paul On Feb 11, 11:17 pm,surreal5335surrea...@hotmail.com wrote: I am working making an intro page to a photo site and I need the image to fade in slowly after the site finishes loading. I believe I have the jquery correct but something is obviously wrong. Right the now the image is hidden, but it wont fadeIn. I am also trying to get the text Please wait for site to load to slowly fadeOut during this, then after all thats done, fadeIn the Enter Site text. Here is the code I am using for it. So far only a few things are working properly. script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/ jquery.min.js/script script type=text/javascript $(document).ready(function(){ $(span).ready(function(){ $(this).removeClass(pic){ $(this).fadeIn(4000); } }, function() { $(div).fadeOut(6000); }, function() { $(a#site).removeClass(site); $(this).fadeIn(1000); }); }); /script style type=text/css a.site {display: none} span.pic {display: none} table.position {position: center} div.position {text-align: center} /style /head body table border=1 class=position tr td span id=photo class=pic img src=/test/land_scape_5.png /span /td /tr tr td div class=positionPlease wait for site to load/div a href=# class=site id=site style=text-align: rightEnter Site/a /td /tr /table Here is the link to the page to see whats it giving me: http://royalvillicus.com/test/photo.html I appreciate all the help
[jQuery] Re: Browser locking up -- please help!
Any other scripts on the page? What does the HTML looks like? Try putting a complete version at jsbin.com exhibiting the lock-up, nothing looks wrong in the code you posted. cheers, - ricardo On Feb 12, 3:25 pm, Shane shanep...@gmail.com wrote: Thanks for Viewing, I have one page that locks up all browsers except Mac/Safari. It was more complex, but I whittled the jQuery code down to the bare essentials. Even though it's super-simple now, it still hangs for 15 seconds (FireFox is completely non-responsive during this) and ends with a script loop error message. Basically, I have a table where users click on a table row to direct them to that entry's page. (I put the href in the tr title attr) What in the world is wrong here? script src='js/jquery.js' type='text/javascript'/script script type='text/javascript' //![CDATA[ $(document).ready(function(){ $(#target tr).click(function(){ var title = $(this).attr(title); window.location.href = title; }); $(.hideinit).hide(); $(#ajax-load-img).hide(); }); //]] /script
[jQuery] Re: Is there a way to make a textarea that auto expands as needed?
Hi Rick, no problem, just checking :] I posted a mock-up of what could be done. Unfortunately it is not reliable, as word-wrapping ruins the column/character count. The 'expandable' plugin seems to have found a nice way to get around that. http://jsbin.com/ozocu/edit cheers, - ricardo , too. Thanks, Karl Rick From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Karl Swedberg Sent: Thursday, February 12, 2009 1:05 PM To: jquery-en@googlegroups.com Subject: [jQuery] Re: Is there a way to make a textarea that auto expands as needed? If Ricardo's solution doesn't work for you, you could try Brandon Aaron's plugin. http://github.com/brandonaaron/jquery-expandable/tree/master --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Feb 12, 2009, at 8:14 AM, Ricardo Tomasi wrote: Did you skip my previous message? On Feb 12, 11:02 am, Rick Faircloth r...@whitestonemedia.com wrote: Ideas, anyone? -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Rick Faircloth Sent: Wednesday, February 11, 2009 6:56 PM To: jquery-en@googlegroups.com Subject: [jQuery] Is there a way to make a textarea that auto expands as needed? I'd like to figure out a way to make a textarea that expands with text input when necessary and shrinks, also, if possible...and without scrollbars. I've looked around, but haven't found a solution that does everything. Anyone know if that's possible with jQuery? Or how to do it? Rick
[jQuery] Re: Is A Child Of?
You can shave a few ms off that by using the current object itself, and cacheing the other element: jQuery.fn.in = function(a){ var a = $(a)[0]; return !!this.parents().filter(function(){ return this === a;}).length; }; Also be aware that this actually checks if the element is a *descendant* of the other, not just a child. For a simple (and faster) 'childOf' check use this: jQuery.fn.childOf = function(a){ var p = false; this.each(function(){ if (this.parentNode == a) p = true; }); return p; }; cheers, - ricardo On Feb 11, 1:56 pm, Ami aminad...@gmail.com wrote: The Best solution: I have writed a very small plugin (1 line) for that, by using the code of Richard jQuery.fn.childOf=function(a){var b=this;return ($(b).parents().filter (function() { return this === $(a)[0]; }).length )} For Example: $(div).childOf(document.body) $(div).childOf($(document.body)) I hope that there is no bugs in this code. On 22 ינואר, 11:25, James Hughes j.hug...@kainos.com wrote: Hi, This is probably a really easy question an I apologise if it appear stupid but I am clueless right now. Given 2 jQuery objects (a,b) how can I tell if b is a child of a? James This e-mail is intended solely for the addressee and is strictly confidential; if you are not the addressee please destroy the message and all copies. Any opinion or information contained in this email or its attachments that does not relate to the business of Kainos is personal to the sender and is not given by or endorsed by Kainos. Kainos is the trading name of Kainos Software Limited, registered in Northern Ireland under company number: NI19370, having its registered offices at: Kainos House, 4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland. Registered in the UK for VAT under number: 454598802 and registered in Ireland for VAT under number: 9950340E. This email has been scanned for all known viruses by MessageLabs but is not guaranteed to be virus free; further terms and conditions may be found on our website -www.kainos.com
[jQuery] Re: Increment Value. What am I doing wrong?
Increment/decrement is for variables. You can't use it directly on a number. Try '3--'. Make it simple, if you use subtraction the type conversion is done for you: $index = $('#Index'); val = $index.val()-1; On Feb 11, 2:37 pm, shapper mdmo...@gmail.com wrote: You mean the following: $index = $('#Index'); parseInt($index.val())--; This still gives me the same error. Could someone, please, tell me how to do this? Thanks, Miguel On Feb 11, 6:38 am, Ralph Whitbeck ralph.whitb...@gmail.com wrote: Karl is right, you need to convert it from a string first. shapper wrote: Hello, I have an input on my page as follows: input id=Index name=Index type=hidden value=0 / I am trying to increase and decrease the value of the input as follows: $index = $('#Index'); $index.val()--; I always get an error: invalid assignment left-hand side What am I doing wrong? Thanks, Miguel
[jQuery] Re: Safe Ajax Calls?
*and don't forget to return false or do e.preventDefault() $('.aj-link').click(function(){ var page = $(this).attr('href'); $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); return false; }); On Feb 11, 4:57 pm, Ricardo Tomasi ricardob...@gmail.com wrote: $('.aj-link').click(function(){ var page = $(this).attr('href'); $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); }); http://docs.jquery.com/Selectorshttp://docs.jquery.com/Eventshttp://docs.jquery.com/Ajax On Feb 11, 10:40 am, SoulRush saavedra@gmail.com wrote: I though that it would be nice to make the links with a certain format like: a href=ajaxProcess.php?var1=var1valuevar2=var2value class=aj- link link/a And make a selection for that kind of links with jquery, that takes these data to make an ajax call with post... That selection should be in a .js outside of the source of the pages and packed or something... What do you think? Please I need some feedback :) Greetings! On 9 feb, 17:02, SoulRush saavedra@gmail.com wrote: By the way, the first parameter takes the vars to send... so in the pages I've to dynamically set varname1=value1varname2=value2 On 9 feb, 10:40, SoulRush saavedra@gmail.com wrote: Hi! I'm kind of new at the world of ajax and jquery and i'm starting to make a site with them. In my site i've created a single function (in the header) called ajaxQry(...) which takes some parameters like, url to make post or get, if I need GEt or POST, the data type of the query, a success function and an error function. Anyway, it look like this: function ajaxQry(sendVars, url, returnType, backFunction, errorFunction){ $.ajax({ type: POST, url: ajax/+url+.asp?nocache=+Math.random(), data: sendVars, success: backFunction, //ussully this loads the content in the main page as html dataType: returnType, error: errorFunction }); } Everything works great but i don't know if there's a better way to do this, because in many events of the site I call this function... And I'm starting to think that it's pretty insecure What do you think? By the way i ussually call the url file (see the function) and return HTML content, and then i load it in the page with $(selector).html(); is that okay? Thanks! and sorry for my english :$
[jQuery] Re: document.createComment usage - can be improved?
It's part of the DOM Level 1 specs, should be supported by all current browsers: http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-createComment You can overwrite it though, document.createComment = null || anything; On Feb 11, 8:20 am, Marc Palmer wangjamm...@googlemail.com wrote: Hi, I'm new to jQuery. I had to use 1.3.1 with the HtmlUnit Java web testing library and we found that with publicly released versions of HtmlUnit it fails because the JS engine cannot find the function document.createComment Is this a standard DOM method or something widely supported by browsers? I looked in the jQuery source, and this is only used once, and only as part of detection of other bugs: (function(){ // Check to see if the browser returns only elements // when doing getElementsByTagName(*) // Create a fake element var div = document.createElement(div); div.appendChild( document.createComment() ); If there is a possibility that some browsers do not support createComment then shouldn't that code check first for the existence of the function? Just seems that would be in the proper spirit of jQuery, as I understand it so far. $0.02 ~ ~ ~ Marc Palmer Blog http://www.anyware.co.uk Twitter http://twitter.com/wangjammer5 Grails Rocks http://www.grailsrocks.com
[jQuery] Re: using :has with selector
Try doing it in two steps: $(#tableid tbody tr:has(td.someclass)).filter(':contains (mytext)').doSomething() On Feb 10, 7:57 pm, SteelRing steelr...@gmail.com wrote: Anyone can think of a reason why this shouldn't work? I'm trying to select the Row (tr) where the cell of td with class someclass contains mytext. Since I want to work on the row (tr) itself, I need to use :has because I don't need to select the td itself. Am I wrong or am I wrong? $(#tableid tbody tr:has(td.someclass:contains(mytext))).dosomething ();
[jQuery] Re: Select all even row in table that are not with a specified class.
Yes, you can. In doubt, just try it, it doesn't hurt :) $(table.font_quotazioni tr:odd:not(.highlight,.midlight)).addClass (even); $(table.font_quotazioni tr:odd:not(.highlight):not (.midlight)).addClass(even); $(table.font_quotazioni tr:odd).not(.highlight, .midlight).addClass (even); On Feb 11, 9:12 am, m.ugues m.ug...@gmail.com wrote: Is it possibile to add a condition in or to the not condition? jQuery(table.font_quotazioni tr:odd:not ('.highlight','.midlight')).addClass(even); Kind regards Massimo Ugues On Dec 23 2008, 10:04 pm, aquaone aqua...@gmail.com wrote: Sure. $(table.font_quotazioni tr:even:not('.midlight'))...http://docs.jquery.com/Selectors/not#selector stephen On Tue, Dec 23, 2008 at 10:01, m.ugues m.ug...@gmail.com wrote: Hallo all. I got a table like this table class=font_quotazioni thead tr th title=Data Contabile class=chars4Nome/th /tr /thead tbody tr class=midlight tdfoo/td /tr tr tdfoo/td /tr tr tdfoo/td /tr /tbody /table In my document.ready I set a class on even rows $(table.font_quotazioni tr:even).addClass(even); I would like to exclude all the rows that got a certain class (e.g tr class=midlight ) Is it possible?
[jQuery] Re: Safe Ajax Calls?
$('.aj-link').click(function(){ var page = $(this).attr('href'); $('#targetDIV').load('ajax/'+page+'nocache='+Math.random()); }); http://docs.jquery.com/Selectors http://docs.jquery.com/Events http://docs.jquery.com/Ajax On Feb 11, 10:40 am, SoulRush saavedra@gmail.com wrote: I though that it would be nice to make the links with a certain format like: a href=ajaxProcess.php?var1=var1valuevar2=var2value class=aj- link link/a And make a selection for that kind of links with jquery, that takes these data to make an ajax call with post... That selection should be in a .js outside of the source of the pages and packed or something... What do you think? Please I need some feedback :) Greetings! On 9 feb, 17:02, SoulRush saavedra@gmail.com wrote: By the way, the first parameter takes the vars to send... so in the pages I've to dynamically set varname1=value1varname2=value2 On 9 feb, 10:40, SoulRush saavedra@gmail.com wrote: Hi! I'm kind of new at the world of ajax and jquery and i'm starting to make a site with them. In my site i've created a single function (in the header) called ajaxQry(...) which takes some parameters like, url to make post or get, if I need GEt or POST, the data type of the query, a success function and an error function. Anyway, it look like this: function ajaxQry(sendVars, url, returnType, backFunction, errorFunction){ $.ajax({ type: POST, url: ajax/+url+.asp?nocache=+Math.random(), data: sendVars, success: backFunction, //ussully this loads the content in the main page as html dataType: returnType, error: errorFunction }); } Everything works great but i don't know if there's a better way to do this, because in many events of the site I call this function... And I'm starting to think that it's pretty insecure What do you think? By the way i ussually call the url file (see the function) and return HTML content, and then i load it in the page with $(selector).html(); is that okay? Thanks! and sorry for my english :$
[jQuery] Re: Increment Value. What am I doing wrong?
Try this: 5-2 == 3; If you need to increment you can't just use a '+' to convert the string, or parseInt/Number as everyone already pointed out. shapper: $index = $('#Index'); $index.val( +$index.val()+1 ); cheers, - ricardo On Feb 11, 4:47 pm, brian bally.z...@gmail.com wrote: On Wed, Feb 11, 2009 at 1:23 PM, Ricardo Tomasi ricardob...@gmail.com wrote: Increment/decrement is for variables. You can't use it directly on a number. Try '3--'. Make it simple, if you use subtraction the type conversion is done for you: $index = $('#Index'); val = $index.val()-1; Except, as Karl pointed out, val() will return a string. var val = parseInt($index.val()); $index.val(--val);
[jQuery] Re: trigger click event of anchor endless recursion
add event.stopPropagation() to the click listener function on a, that way it won't fire the click for the parent TD. - ricardo On Feb 11, 3:40 pm, johnallan jral...@hotmail.com wrote: jquery 1.3.1 jq(#miniCalendarTable td).hover( function(){ jq(this).addClass(hover) }, function(){ jq(this).removeClass(hover) } ).click(function(){ jq(this).children(a).trigger(click); }); this is my script.. i swear I have done this before but maybe not. the hover works fine... but when the click function runs I get endless recursion... when i return the length of the children(a) it is 1 any ideas?
[jQuery] Re: Replace part of a src= value
That's a simple Regular Expression (present in most programming languages, not just JS) that does a case-insensitive (/i) for '.png' at the end ($) of the string. See here: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Regular_Expressions You might want to filter the img elements first, depending on how many of those you have it could improve performance (better to test it). $(img[src$=.png]).each(... and then use a simple string replace: .replace('.png', '.jpg'); //is there any real chance of having .png in the middle of the filename? cheers, - ricardo On Feb 11, 5:29 pm, -e-train etrai...@gmail.com wrote: Thanks James, this seems to work well. on the replace section, can you explain what this is doing? /.png$/i, i am not a javascript coder. it works, but i would like to understand what is going on. cheers. -e- On Feb 10, 6:14 pm, James james.gp@gmail.com wrote: Un-tested, but maybe something like this: if ($.browser.msie $.browser.version == '6.0') { $(img).each(function() { var new_src = $(this).attr(src).replace(/.png$/i, '.jpg'); $(this).attr(src, new_src); }); } Note that $.browser is deprecated from jQuery 1.3, but still available for use. On Feb 10, 3:26 pm, -e-train etrai...@gmail.com wrote: Hi All, I am new to jQuery and am having a hard time figuring out what i am looking for in the docs an don this forum. What i want to do is create a little jquery script that checks to see if the browser is msie and browser.version is 6.0 I have that part done: jQuery.each(jQuery.browser, function(i, val) { if(i==msie jQuery.browser.version.substr(0,3)==6.0) { } } }); I was able to display an alert. cool. now what I would like to do is if the above is true and the agent is msie 6.0 then i want to find all img tags that have a src=some-image.png and replace the .png with .jpg i think i need to use the [attribute$=value] selector. and then write something that is the equivalent of if (img[source$='png']) then replace (img[source$='png']) with (img[source$='jpg']) but i don't know how to write javascript very well... any help is appreciated. cheers, -e-
[jQuery] Re: Replace part of a src= value
Looks like we posted at the exact same time! :] Correcting myself again: you should really use the regex, as the simple string replace is case-sensitive. On Feb 11, 5:40 pm, Ricardo Tomasi ricardob...@gmail.com wrote: That's a simple Regular Expression (present in most programming languages, not just JS) that does a case-insensitive (/i) for '.png' at the end ($) of the string. See here:https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Regular_Ex... You might want to filter the img elements first, depending on how many of those you have it could improve performance (better to test it). $(img[src$=.png]).each(... and then use a simple string replace: .replace('.png', '.jpg'); //is there any real chance of having .png in the middle of the filename? cheers, - ricardo On Feb 11, 5:29 pm, -e-train etrai...@gmail.com wrote: Thanks James, this seems to work well. on the replace section, can you explain what this is doing? /.png$/i, i am not a javascript coder. it works, but i would like to understand what is going on. cheers. -e- On Feb 10, 6:14 pm, James james.gp@gmail.com wrote: Un-tested, but maybe something like this: if ($.browser.msie $.browser.version == '6.0') { $(img).each(function() { var new_src = $(this).attr(src).replace(/.png$/i, '.jpg'); $(this).attr(src, new_src); }); } Note that $.browser is deprecated from jQuery 1.3, but still available for use. On Feb 10, 3:26 pm, -e-train etrai...@gmail.com wrote: Hi All, I am new to jQuery and am having a hard time figuring out what i am looking for in the docs an don this forum. What i want to do is create a little jquery script that checks to see if the browser is msie and browser.version is 6.0 I have that part done: jQuery.each(jQuery.browser, function(i, val) { if(i==msie jQuery.browser.version.substr(0,3)==6.0) { } } }); I was able to display an alert. cool. now what I would like to do is if the above is true and the agent is msie 6.0 then i want to find all img tags that have a src=some-image.png and replace the .png with .jpg i think i need to use the [attribute$=value] selector. and then write something that is the equivalent of if (img[source$='png']) then replace (img[source$='png']) with (img[source$='jpg']) but i don't know how to write javascript very well... any help is appreciated. cheers, -e-
[jQuery] Re: Is A Child Of?
'return true' inside the each callback works like a 'continue', skipping to next iteration. The value is never returned to the outside scope (would break chaining). cheers, - ricardo On Feb 11, 6:33 pm, Ami aminad...@gmail.com wrote: You can shave a few ms, and memory: *** jQuery.fn.childOf = function(a){ this.each(function(){ if (this.parentNode == a) return true; }); return false;}); *** On Feb 11, 8:18 pm, Ricardo Tomasi ricardob...@gmail.com wrote: You can shave a few ms off that by using the current object itself, and cacheing the other element: jQuery.fn.in = function(a){ var a = $(a)[0]; return !!this.parents().filter(function(){ return this === a;}).length; }; Also be aware that this actually checks if the element is a *descendant* of the other, not just achild. For a simple (and faster) 'childOf' check use this: jQuery.fn.childOf = function(a){ var p = false; this.each(function(){ if (this.parentNode == a) p = true; }); return p; }; cheers, - ricardo On Feb 11, 1:56 pm, Ami aminad...@gmail.com wrote: The Best solution: I have writed a very small plugin (1 line) for that, by using the code of Richard jQuery.fn.childOf=function(a){var b=this;return ($(b).parents().filter (function() { return this === $(a)[0]; }).length )} For Example: $(div).childOf(document.body) $(div).childOf($(document.body)) I hope that there is no bugs in this code. On 22 ינואר, 11:25, James Hughes j.hug...@kainos.com wrote: Hi, This is probably a really easy question an I apologise if it appear stupid but I am clueless right now. Given 2 jQuery objects (a,b) how can I tell if b is achildof a? James This e-mail is intended solely for the addressee and is strictly confidential; if you are not the addressee please destroy the message and all copies. Any opinion or information contained in this email or its attachments that does not relate to the business of Kainos is personal to the sender and is not given by or endorsed by Kainos. Kainos is the trading name of Kainos Software Limited, registered in Northern Ireland under company number: NI19370, having its registered offices at: Kainos House, 4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland. Registered in the UK for VAT under number: 454598802 and registered in Ireland for VAT under number: 9950340E. This email has been scanned for all known viruses by MessageLabs but is not guaranteed to be virus free; further terms and conditions may be found on our website -www.kainos.com
[jQuery] Re: Order Items. Please help me. Thank You.
Probably not the most efficient function, but should work: $('#ThemesList li').each(function(index){ $('input:hidden', this).each(function(){ var fixName = $(this).attr('name').replace(/\[\d\]/, '['+index +']'); $(this).attr('name', fixName); }); }); - ricardo On Feb 11, 7:19 pm, shapper mdmo...@gmail.com wrote: Hello, I am adding and removing a items from a list, using JQuery, which is rendered has follows: ol id=ThemesList li input type=hidden name=Themes[0].Subject value=A / input type=hidden name=Themes[0].Levels value=L1,L2 / input type=hidden name=Themes[0].Description value=Paper / /li li input type=hidden name=Themes[2].Subject value=B / input type=hidden name=Themes[2].Levels value=L1,L5 / /li li input type=hidden name=Themes[5].Subject value=D / input type=hidden name=Themes[5].Levels value=L2,L4 / input type=hidden name=Themes[5].Description value=Book / /li /ol Every time I add or remove a Theme I need to be sure that the list is ordered (name) starting with Themes[0]. So basically I need to loop through each list item in list ThemesList. - In first list item all HIDDEN inputs names should start with Themes [0] - In second list item all HIDDEN inputs names should start with Themes [1] ... So in this example, Themes[2]. ... would become Themes[1]. ... and Themes[5]. ... would become Themes[2]. ... Could someone please help me out? I have no idea how to do this. Thanks, Miguel
[jQuery] Re: Is there a way to make a textarea that auto expands as needed?
My guess would be to count the character number on keypress and increase height accordingly. textarea ... cols=40/textarea var $text = $('textarea'), oHeight = $text.height(), cols = +$text.attr('cols'), lineHeight = parseInt($text.css('line-height')); $text.bind('keypress', function(){ ln = $text.val().length, m = ln%cols; if (ln !m) $text.animate({height: oHeight + (ln/cols) *lineHeight}); }); The column number/character count doesn't seem reliable, but it kinda works: http://jsbin.com/odipi cheers, - ricardo On Feb 11, 9:55 pm, Rick Faircloth r...@whitestonemedia.com wrote: I'd like to figure out a way to make a textarea that expands with text input when necessary and shrinks, also, if possible...and without scrollbars. I've looked around, but haven't found a solution that does everything. Anyone know if that's possible with jQuery? Or how to do it? Rick
[jQuery] Re: Removing all styles from an element-
You could a use kind of CSS reset for your container. I usually don't like '*' declarations but this seems fit here: #myModule * { margin:0; padding:0; font-family:Arial; color:#000; height:auto; width:auto } On Feb 11, 11:09 pm, Nic adaptive...@gmail.com wrote: The scenario: I am developing a module that will live on any page it's requested to live on (any website). The issue is that if the website it's on has a broad style definition (ie. p { margin: 20px; }), this will affect my elements (in addition to the styles I define). Is there a way I can ensure that only the styles I apply are used, or to clear all styles of my elements before I apply my own? So if someone has such a definition on their page, it won't effect my module. I know I could explicitly redefine the style myself, but there is no way of telling ahead of time what styles will be defined (without defining every single css property for every single element)- so a catch all would be nice. Thanks, Nichttp://www.twitter.com/nicluciano Sent from my iPhone
[jQuery] Re: Finding the last sibling.
$(this).parent().children(':last') //or :last-child - assuming 'this' is the input element On Feb 12, 3:09 am, Risingfish risingf...@gmail.com wrote: Thanks Nic, How about if I'm using the input tag as the base? Can I do something like $(self:parent:last-child) ? On Feb 11, 8:13 pm, Nic Luciano adaptive...@gmail.com wrote: $(div :last-child); (or this wacky way I tried before I learned CSS selectors $(div).children()[$(div).children().size() - 1])...) Nic Lucianohttp://www.twitter.com/niclucianohttp://www.linkedin.com/in/nicluciano On Wed, Feb 11, 2009 at 9:49 PM, Risingfish risingf...@gmail.com wrote: Hi James, apologize for not being more precise. I'm using the input element as my base reference. So using that input element, I want to get the last sibling under the div. You are correct that if the span is not then the input is what I want. I may need to add more tags later (I'm sure you know hoe the development process goes when customers are involved. :) ), so a reliable way to get the last tag would be nice. Thanks! On Feb 11, 7:21 pm, James james.gp@gmail.com wrote: When you say last sibling in a parent, what does that mean? Which element is your base reference? In your example: div input .. / span.../span /div Do you mean your div is the base reference, and you want to find the last child (thus, span) relative to that? And if span is not there, you want input? On Feb 11, 4:12 pm, Risingfish risingf...@gmail.com wrote: Before I accidentally hit enter, this is what I was trying to type: :) div input .. / span.../span /div The span might or might not be there, so I would like to just get the last sibling in a parent. Thanks!
[jQuery] Re: A small incompatibility about selector on Jquery 1.3.1
Try $('#zz input[readonly=]:first') There are a few selector bugs in 1.3.1. Most have already been fixed for 1.3.2. cheers, - ricardo On Feb 12, 12:53 am, jack datac...@gmail.com wrote: The following works on before Version: $('#zz input:not([readonly]):first').focus().select() On Ver 1.3.1, it won't work unless you change to: $('#zz input:not([readonly=]):first').focus().select()
[jQuery] Re: The order of these conditions should not matter
What do you mean by overriden? Just copied your code over and it seems to work fine. http://jsbin.com/efeje http://jsbin.com/efeje/edit - ricardo On Feb 10, 3:07 pm, Thomas Allen thomasmal...@gmail.com wrote: Here's my JS:http://pastebin.com/m6091a365 And the accompanying HTML:http://pastebin.com/m30c57ea6 For some reason, the if($(pay_... condition that comes first gets overridden by the one that follows it. The :checked states you see in the JS are mutually exclusive because they are a part of the same radio group (as seen in the HTML). The showCC and showCheck functions work perfectly in the focus() context (they switch normally). The reason that I'm setting this up this way is so that a user will only see the payment region that they need to see. Thanks, Thomas Allen
[jQuery] Re: The order of these conditions should not matter
Doh. I'm blind. $(#pay_cc:checked) will always be 'true'. even if the element is not found an object will be returned. You have to check for .length or size () if($(#pay_cc:checked).length) showCC(); if($(#pay_check:checked).length) showCheck(); cheers, - ricardo On Feb 10, 5:29 pm, Thomas Allen thomasmal...@gmail.com wrote: It works fine for the focus event. The purpose of the conditionals is to ensure that the correct payment field pops up if the page is reloaded/revisited. For whatever reason, on a page reload, showCheck() always fires, even line 1's condition returns true and line 2's returns false (I've tested this in Firebug's console, and the conditionals work fine when entered individually). if($(#pay_cc:checked)) showCC(); if($(#pay_check:checked)) showCheck(); This is very problematic. If I remove the second line, the first line works as expected, and I observe the same behavior when I try these conditionals reverse order (Check first, causing CC to always override it). Thomas On Feb 10, 2:23 pm, Ricardo Tomasi ricardob...@gmail.com wrote: What do you mean by overriden? Just copied your code over and it seems to work fine. http://jsbin.com/efejehttp://jsbin.com/efeje/edit - ricardo On Feb 10, 3:07 pm, Thomas Allen thomasmal...@gmail.com wrote: Here's my JS:http://pastebin.com/m6091a365 And the accompanying HTML:http://pastebin.com/m30c57ea6 For some reason, the if($(pay_... condition that comes first gets overridden by the one that follows it. The :checked states you see in the JS are mutually exclusive because they are a part of the same radio group (as seen in the HTML). The showCC and showCheck functions work perfectly in the focus() context (they switch normally). The reason that I'm setting this up this way is so that a user will only see the payment region that they need to see. Thanks, Thomas Allen
[jQuery] Re: jQuery / FF3 problem using show()
From the docs: Note: Please make sure that all stylesheets are included before your scripts (especially those that call the ready function). Doing so will make sure that all element properties are correctly defined before jQuery code begins executing. Failure to do this will cause sporadic problems, especially on WebKit-based browsers such as Safari. http://docs.jquery.com/Events/ready#fn cheers, - ricardo On Feb 10, 4:36 pm, JohnnyCee jfcardi...@gmail.com wrote: On Feb 10, 1:14 pm, pete higgins phigg...@gmail.com wrote: moving the link above the script will likely fix this. Pete, Thanks! That did fix it. I presume it's a timing/sequence issue related to when ready() is called versus when the linked CSS file is loaded. After posting the first message I discovered that the issue affects Chrome and Safari, too. John
[jQuery] Re: Does it hurt to call functions that don't do anything on the page?
I think the issue is that all of the functions are declared on the same external JS file. So you can't check for the function itself, as it will always exist, you need to check for some condition in the page. All of this will be inside $(document).ready on the external file. There are many other possibilities, a meta tag, using the title or any other text/element on the page. The choice boils down to how the whole site/app is structured and development practices in use. cheers, - ricardo On Feb 9, 3:29 pm, mkmanning michaell...@gmail.com wrote: @Nicolas - I'm curious as to why you find Ricardo's easiest? Ricardo's first solution would work, but to my mind adds extra complexity. You're adding a dependency on the presence of elements in the markup to execute your functions. If you work, as I currently do, in a multi-developer environment, it's very easy for someone to change the id of the element you're using, or perhaps remove it completely, which would immediately stop the functions from being called. They could also add that element to a page using a different identifier, and now that page would match two of Ricardo's if statements, calling functions that won't exist and so you're back to the original issue. This latter condition means you have to make sure you have a unique identifier element for every page, or follow Ricardo's second suggestion and use a unique class on the body tag of every page. One thing not apparent in his example is that the user may want multiple functions to run on each page, for example: page 1: functions 1,2, 4 page 2: functions 3,4 6 etc. This increases the complexity of the if statements and which functions go where, and seems more likely to break over time as functions get added or removed. My suggestion of just keeping an array of functions in one location (the external js), and checking for the presence of the function on domready and executing it if found, rather than a 'middle-man' element that has to stand in for one or more functions, seems much more direct--to me at least :) Maybe I'm missing something that makes Ricardo's seem to be easiest? On Feb 9, 2:26 am, Nicolas R ruda...@googlemail.com wrote: I not sure if this suits you, but you could split your functions to separate files and then lazy load each js file as necessary. In such casehttp://nicolas.rudas.info/jQuery/getPlugin/maybe helpful Otherwise I find Ricardo's suggestion the easiest. You could also do some time tests to check whethercallingthese functions when not really needed effects performance, and act accordingly On Feb 9, 3:33 am, mkmanning michaell...@gmail.com wrote: *Tab+spacebar and it posts :P You could put your list of functions in an array in your external js, then call them on the window object in a loop: $(function() { var funcs = [ 'ManageCategoriesClick', 'HideByDefault', 'PrepareSplitForm', 'SetUpAdvertPopup', 'CheckAll', 'CheckNone', 'EditCategoryInPlace', 'PreparePaneLinks', 'PrepareToolTips' ] $.each(funcs,function(i,f){ if(typeof(window[f]) == 'function'){ window[f](); } }); }); On Feb 8, 5:21 am, Beau zar...@gmail.com wrote: Thanks for the ideas everyone! @Stephan: Yes, it's in an external JS file. I'd prefer to not have to do any inline javascript. I've considered it, but thanks for the suggestion! @Ricardo: Thanks for those. I may end up doing a variation of them. On Feb 8, 4:50 am, Stephan Veigl stephan.ve...@gmail.com wrote: Hi I guess you have your $().ready()functionin an external js file, otherwise you could customize it for the according html page. Another construct similar to Ricardos one, but a bit more flexible: Use a global variable in every html file to specify the init functions you want to call for this page: script type=text/javascript myInitFxn = [ManageCategoriesClick, HideByDefault, PrepareSplitForm,...]; /script ready.js: $().ready(function(){ for(var i in myInitFxn) { myInitFxn[i](); // call initfunction } }); by(e) Stephan 2009/2/8 brian bally.z...@gmail.com: On Sat, Feb 7, 2009 at 11:21 PM, Ricardo Tomasi ricardob...@gmail.com wrote: Alternatively you could add a different class to the body of each page, then use this rather amusing construct: $(document).ready((function(){ var is =function(v){ return ++document.body.className.indexOf(v) }; return( is('categories') ? ManageCategoriesClick : is('hidebydefault') ? HideByDefault : is('form') ? PrepareSplitForm : is('advert
[jQuery] Re: jquery, OOP and this - Problem
just stay aware of the scope: var oldthis = this; this.slide=function(){ $(this.container_selector_contents).fadeOut(1000, function(){ oldthis.setContent(); oldthis.fadeIn(1000) }); } ; On Feb 9, 3:13 pm, Creativebyte michaelhaszpru...@googlemail.com wrote: Hello group, I got a problem with a JS class I am writing. I got the following piece of code: this.slide=function(){ $(this.container_selector_contents).fadeOut(1000, function(){ this.setContent(); this.fadeIn(1000) }); } The problem is, that inside the fadeOut() function this is now not the class but the jQuery element. So, how can I access my classes methods and variables again sine I can't use this? Thanks for your help!
[jQuery] Re: jquery, OOP and this - Problem
Oh, I thought setContent() was one of his class' methods. Does it make sense to do something like this.slide=function() {.. on a jQuery object? On Feb 9, 5:57 pm, Eric Garside gars...@gmail.com wrote: Yea, the scope should be fine. You just have to wrap this in $() when using the reference to the element. On Feb 9, 2:09 pm, SoulRush saavedra@gmail.com wrote: Did you try with $(this).setContent(); instead of this.setContent(); ? On 9 feb, 14:13, Creativebyte michaelhaszpru...@googlemail.com wrote: Hello group, I got a problem with a JS class I am writing. I got the following piece of code: this.slide=function(){ $(this.container_selector_contents).fadeOut(1000, function(){ this.setContent(); this.fadeIn(1000) }); } The problem is, that inside the fadeOut() function this is now not the class but the jQuery element. So, how can I access my classes methods and variables again sine I can't use this? Thanks for your help!
[jQuery] Re: New jQuery Conditional Chain Plugin
I still prefer the old ternary operator way: $.ajax('url.php', function(data){ $('#result').addClass(data.success ? 'ui-state-highlight' : 'ui- state-error'); }, 'json'); Any possibilities I'm missing here? On Feb 9, 5:12 pm, Eric Garside gars...@gmail.com wrote: Hey guys, I had an idea this morning which quickly turned into a small but, I think powerful, plugin. I'd love some review on it from the list, to see if anyone can see any glaring errors I missed, or has an easier/ already done way of doing it. The source code and some examples are located here:http://snipplr.com/view/12045/jquery-conditional-chains/ The basic idea was to add functionality to jQuery to conditionally execute functions on the chain, based on dynamic values. Take for example: $.ajax('url.php', function(data){ $('#result').cond(data.success, 'addClass', 'ui-state- highlight').cond(!data.success, 'addClass', 'ui-state-error'); }, 'json'); Instead of $.ajax('url.php', function(data){ if (result.data) $('#result').addClass('ui-state-highlight'); else $('#result').addClass('ui-state-error'); }, 'json'); Also, it has functionality to stop/resume the chain based on boolean variables. $.ajax('url.php', function(data){ $('#result') .stop(!data.success).addClass('ui-state-highlight').text('Success! Excelsior!') .resume(!data.success)).addClass('ui-state-error').text('Failure! Oh Noes!') }, 'json'); Thoughts? Comments? Ideas for improvement? What do ya'll think?
[jQuery] Re: Next/Previous element in each loop
You can take advantage of the index passed to each. What you posted is very close to working: $(function() { var divs = $(div); divs.each(function(i){ var prev = divs.eq(i-1).text(); var next = divs.eq(i+1).text(); alert(prev + - + next); }); }); There's no need to check for the existance of a previous/next element, as jQuery fails silently. cheers, - ricardo On Feb 9, 5:25 pm, Stephan Veigl stephan.ve...@gmail.com wrote: Hi Adrian, as mkmanning already said, when you want to get the next / prev element from the same selector, simply access the array. In this case I prefer a for (var i=0; ips.length; i++) {...} loop instead of the $.each for performance reasons and readability, but that's personal taste. by(e) :-) Stephan 2009/2/9 mkmanning michaell...@gmail.com: $(p) is an array, so you could just use the index: var ps = $(p); //cache ps.each(function(i,d) { var prevP = i0?$(ps[i-1]):false; /* however you want to deal with there not being a prev */ var nextP = ips.length-1?$(ps[i+1]):false; /* however you want to deal with there not being a next */ if(prevP){ console.log($(prevP).html()); } if(nextP){ console.log($(nextP).html()); } //if you only want p's that have a prev AND next, you can do this if(i0 ips.length-1){ console.log( $(ps[i-1]).html() + ', ' + $(ps[i+1]).html() ); } }); On Feb 9, 8:55 am, Adrian Lynch adely...@googlemail.com wrote: This explains better what I'm after: $(p).each(function(i) { var prevP = $(this).parent().prev().children(p); var nextP = $(this).parent().next().children(p); console.info(prevP.html()); console.info(nextP.html()); }); div p1/p div spanThis is next/span /div /div div div spanThis is previous/span /div p2/p /div div p3/p /div I want to refer to the next p in the each() loop but $(this).next()/ prev() refers to the next sibling element in the DOM. So in the example above I'm having to go out to the parent, then get the next/previous, then come in to get the p I want. Now I'm wondering if there's a generic way to do this... By(e) - see! Adrian On Feb 9, 4:44 pm, Adrian Lynch adely...@googlemail.com wrote: That's what I was hoping for, but next() and prev() act on the next and previous elements in the DOM, not in the nodes you're looping over. To demonstrate: $(p).each(function(i) { console.info($(this).next().html()); console.info($(this).prev().html()); }); form action=test.cfm method=post div p1/p div pThis is next/p /div /div div div pThis is previous/p /div p2/p /div div p3/p /div /form Maybe I have to come out to the outer most divs before calling next()/ prev() on it. Adrian On Feb 4, 4:16 pm, Stephan Veigl stephan.ve...@gmail.com wrote: Hi, there are prev() and next() functions doing exactly what you need: $(div).each( function() { var prev = $(this).prev(); var next = $(this).next(); alert( prev.text() + - + next.text() ); }); (I've skipped the extra code for the first and last element for simplicity.) by(e) Stephan 2009/2/4AdrianLynchadely...@googlemail.com: Hey all, I'm loop over some nodes witheach() and I need to look at the next and previous elements for the current iteration. script type=text/javascript $(function() { $(div).each(function(i) { var prev = [SELECTOR FOR PREVIOUS DIV].text(); var next = [SELECTOR FOR NEXT DIV].text(); alert(prev + : + next); }); }); /script div1/div div2/div div3/div Will I have to store a reference to the divs and access it with i in the loop like this: script type=text/javascript $(function() { var divs = $(div); divs.each(function(i) { var prev = ; var next = ; if (i 0) prev = $(divs.get(i - 1)).text(); if (i divs.size() - 1) next = $(divs.get(i + 1)).text(); alert(prev + - + next); }); }); /script div1/div spanSpanner in the works/span
[jQuery] Re: Passing a Index to a function
$(table tr).each(function( index ){ $(this).click(function(){ alert('I am TR number ' + index); }); }); the index() function works on a collection of elements, so you'd have to get them first: $('table tr').click(function(){ alert( $(this).parent().children().index(this) ); }); On Feb 9, 5:48 pm, Pedram pedram...@gmail.com wrote: How COme we could not have access inside the BIND with THIS !! I'm Confused On Feb 9, 7:16 am, Pedram pedram...@gmail.com wrote: I check these two solutions it didn't work ... On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote: On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote: Dear folk, I want to get the index of the TR and send it to the Function , I don't know how to it . this is what I'm trying to do $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc) The DOM 2 HTML TR.rowIndex property should do the job. -- Rob
[jQuery] Re: Access DOM cross-domain
Why not simply use escaped plain text? On Feb 9, 6:04 pm, jay jay.ab...@gmail.com wrote: I'm playing around with writing a server-side script that generates JSONP from content that is downloaded by the script (URL is passed to script from querystring). Is there a better way to do it than to encode it as base64, or is there a work-around that doesn't require any server-side code? I'm basically trying to get access to a given page's DOM cross-domain using minimal server-side code. I suppose one thing that would be needed here is a regex to replace non http src attributes. Here is what I have so far: //test.htm body div id=mydiv/div script src=jquery.js/script script src=jquery.base64.js/script script function callback(e){ alert(e.data); alert($.base64Decode(e.data)); $(#mydiv).html($.base64Decode(e.data));} /script script src=test.aspx?url=www.wikipedia.org/script /body //test.aspx %@ Page Language=C# AutoEventWireup=true % %@ Import Namespace=System % %@ Import Namespace=System.IO % %@ Import Namespace=System.Net % %@ Import Namespace=System.Text % script runat=server void Page_Load( object sender, EventArgs e ){ string url = Request[url] ?? ; Response.Write(callback({data:\+EncodeTo64(Get(url))+\})); Response.End();} string EncodeTo64(string toEncode){ byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes (toEncode); string returnValue = System.Convert.ToBase64String (toEncodeAsBytes); return returnValue;} string Get(string strURL){ WebRequest myWebRequest = WebRequest.Create(http://+strURL); WebResponse myWebResponse = myWebRequest.GetResponse(); Stream ReceiveStream = myWebResponse.GetResponseStream(); Encoding encode = System.Text.Encoding.GetEncoding(utf-8); StreamReader readStream = new StreamReader( ReceiveStream, encode ); return readStream.ReadToEnd();} /script
[jQuery] Re: Next/Previous element in each loop
You're right. And apparently it's still faster to get the element by the array index and re-wrap it in a jQuery object than to use eq(). Some room for improvement in the core there. cheers, - ricardo On Feb 9, 8:23 pm, mkmanning michaell...@gmail.com wrote: And just a final note on performance, as Stephan points out, the for loop is faster than $.each, likewise accessing the elements by array index is quite a bit (~7x) faster than using eq() -- For 5 p elements (average time): Using .eq(): 0.14ms and 20 calls Using array index: 0.02ms 2 calls/4 calls (2 on the first last) Depending upon how many elements you may be operating on, the time difference could become important. On Feb 9, 1:51 pm, mkmanning michaell...@gmail.com wrote: Silently for text(), but it returns null for html() (using Adrian's second example/my example) so you'll most likely want to check for that. On Feb 9, 1:23 pm, Ricardo Tomasi ricardob...@gmail.com wrote: You can take advantage of the index passed to each. What you posted is very close to working: $(function() { var divs = $(div); divs.each(function(i){ var prev = divs.eq(i-1).text(); var next = divs.eq(i+1).text(); alert(prev + - + next); }); }); There's no need to check for the existance of a previous/next element, as jQuery fails silently. cheers, - ricardo On Feb 9, 5:25 pm, Stephan Veigl stephan.ve...@gmail.com wrote: Hi Adrian, as mkmanning already said, when you want to get the next / prev element from the same selector, simply access the array. In this case I prefer a for (var i=0; ips.length; i++) {...} loop instead of the $.each for performance reasons and readability, but that's personal taste. by(e) :-) Stephan 2009/2/9 mkmanning michaell...@gmail.com: $(p) is an array, so you could just use the index: var ps = $(p); //cache ps.each(function(i,d) { var prevP = i0?$(ps[i-1]):false; /* however you want to deal with there not being a prev */ var nextP = ips.length-1?$(ps[i+1]):false; /* however you want to deal with there not being a next */ if(prevP){ console.log($(prevP).html()); } if(nextP){ console.log($(nextP).html()); } //if you only want p's that have a prev AND next, you can do this if(i0 ips.length-1){ console.log( $(ps[i-1]).html() + ', ' + $(ps[i+1]).html() ); } }); On Feb 9, 8:55 am, Adrian Lynch adely...@googlemail.com wrote: This explains better what I'm after: $(p).each(function(i) { var prevP = $(this).parent().prev().children(p); var nextP = $(this).parent().next().children(p); console.info(prevP.html()); console.info(nextP.html()); }); div p1/p div spanThis is next/span /div /div div div spanThis is previous/span /div p2/p /div div p3/p /div I want to refer to the next p in the each() loop but $(this).next()/ prev() refers to the next sibling element in the DOM. So in the example above I'm having to go out to the parent, then get the next/previous, then come in to get the p I want. Now I'm wondering if there's a generic way to do this... By(e) - see! Adrian On Feb 9, 4:44 pm, Adrian Lynch adely...@googlemail.com wrote: That's what I was hoping for, but next() and prev() act on the next and previous elements in the DOM, not in the nodes you're looping over. To demonstrate: $(p).each(function(i) { console.info($(this).next().html()); console.info($(this).prev().html()); }); form action=test.cfm method=post div p1/p div pThis is next/p /div /div div div pThis is previous/p /div p2/p /div div p3/p /div /form Maybe I have to come out to the outer most divs before calling next()/ prev() on it. Adrian On Feb 4, 4:16 pm, Stephan Veigl stephan.ve...@gmail.com wrote: Hi, there are prev() and next() functions doing exactly what you need: $(div).each( function() { var prev = $(this).prev(); var next = $(this).next(); alert( prev.text() + - + next.text() ); }); (I've skipped the extra code for the first and last element for simplicity
[jQuery] Re: Help : Difficulty binding event to selected jQuery object
Maybe it's just a typo, but you're creating a div with the ID toolbar_button_target ...prepend(div class='toolbar_button' id='toolbar_button_target'... and then calling it with a class selector: $(.toolbar_button_target) is that right? On Feb 7, 5:38 pm, James S jamespstrac...@gmail.com wrote: Dear jQuery, Can find plenty of discussion on the use of livequery but little on binding problems which are less dynamic. If you could point out a nice simple thing I'm overlooking then that would be great :) Background: As part of a UI I'm coding I serve a series of working panes. Content is ajaxed into the pane and then livequeries pick out class flags from the loaded content. One such flag is toolbar_button class which signals to lift the element out and make it into a button on the toolbar. Post relocation, toolbar html's something like: ==\/ div class=toolbar div class=toolbar_buttonSave/div div class=toolbar_button Cancel/div div class=kill/div /div ==/\ Along with the toolbar_button class flag, a second flag can be used which clones the function of the button to a new button on the toolbar (for stuff that has to be in place in the html to function - in this case form buttons). These two types of toolbar button creation are dealt with by the following jQuery: ==\/ $(.toolbar_button).livequery(function(){ p=parent_pane($(this)); // Finds the parent pane of the button so it can be added to the correct toolbar if($(this).hasClass('copy_me')){ // If the page element needs to stay in position, copy it to toolbar p.children('.toolbar').prepend(div class='toolbar_button' id='toolbar_button_target'+$(this).val()+/div); $(.toolbar_button_target).css('color','red').click(function(e){ alert('This code is never run!'); }).removeClass('toolbar_button_target'); }else{ // Move it to the toolbar p.children('.toolbar').prepend($(this).remove()); } }); ==/\ Buttons without the copy_me class are successfully transposed and function as they should. However, when adding a copy of a copy_me button the resulting object can be selected (the css() rule in the code above turns it red) but doesn't respond to event binding. Click() function as above doesn't work, nor other events. I can't find any complication with event bubbling, nothing is stopping the propagation. I would be much obliged if someone with a greater insight could point me right on this one. Thanks, James
[jQuery] Re: selector to return the number of rows in a table before the row I just selected
you should be looking at http://docs.jquery.com/Traversing var currentRow = $('table tr').eq(7); var howManyBefore = currentRow.prevAll('tr').length; cheers, - ricardo On Feb 8, 3:23 pm, pantagruel rasmussen.br...@gmail.com wrote: Hi, I am selecting the row of a table. I would like to be able to count how many rows there are in the table before the row I just selected. i suppose there is a jQuery selector that will do this. Thanks
[jQuery] Re: Optimize large DOM inserts
There's no need to use that function to insert the HTML, as the performance improvement comes mostly from emptying the element outside the DOM. To avoid the memory leak, you'd have to remove all the event listeners before destroying it - that's exactly what empty() does (+ clearing any data), and the source of most of it's overhead. You can probably get around that by not attaching any events to the inner elements and use event delegation on the table or live() instead. You might get away with something like this, not sure if it will perform any better: var c = $('#container')[0], parent = c.parentNode, next = c.nextSibling, old = parent.removeChild(c); c = old.cloneNode(false).innerHTML = out.join(''); if (next) next.insertBefore(c); else parent.appendChild(c); setTimeout(function(){ $(old).remove(); }, 200); //give the browser some breathing time then clean up eventsdata from the old element The cleaning up part will be unnecessary if you use event delegation. - ricardo On Feb 6, 9:17 pm, James james.gp@gmail.com wrote: I just noticed in IE6 that using the replaceHTML to clear the DOM with events attached definitely creates memory leak. FF seems to clean it up though. On Feb 6, 1:06 pm, James james.gp@gmail.com wrote: Wow! Wow! Wow! Using that replaceHTML function to empty out the element took practically no time at all! Though I wasn't able to get it to work properly in IE (tried only IE6) as oldEl.innerHTML = html; kept bombing on me with unknown runtime error. I've removed the IE-only part and let it run the rest. It's still many times faster than using $(el).empty(); However, I wasn't able to get replaceHTML to work on inserting HTML into the DOM though. Using the previous suggestions, it would become: replaceHtml('myElementID', out.join('')); but the inserted HTML in 'myElementID' had all of the HTML tags (tr, td, etc.) stripped out for some reason. On Feb 6, 11:48 am, Ricardo Tomasi ricardob...@gmail.com wrote: Now I might have something useful to say! :) I remember this being discussed long ago on the 'replaceHTML' subject. Apparently using .innerHTML on an element that is not in the DOM is much faster (except for IE which is already fast). See here: http://blog.stevenlevithan.com/archives/faster-than-innerhtmlhttp://w.. cheers, - ricardo On Feb 6, 6:28 pm, James james.gp@gmail.com wrote: Big thanks for the optimization! It certainly did optimize the loop processing by several folds! However, for my case, I found that the ultimate bottleneck was the plug-in function that I was using that froze the browser the longest. The actual insert to the DOM took a bit of time also and did freeze the browser, but wasn't too bad even in IE6. By the way, do you have any tips on emptying a large amount of content in the DOM? Such as emptying that whole chunk of HTML that was inserted. That also freezes the browser also. I'm currently using $(el).empty(); and not sure if there's a more optimal solution. Thanks! On Feb 5, 5:25 pm, Michael Geary m...@mg.to wrote: ...there is not much room for improvement left. You just know that when you say that, someone will come along with a 20x-40x improvement. ;-) http://mg.to/test/loop1.html http://mg.to/test/loop2.html Try them in IE, where the performance is the worst and matters the most. On my test machine, the first one runs about 6.3 seconds and the second one about 0.13 seconds. -Mike From: Ricardo Tomasi Concatenating into a string is already much faster than appending in each loop, there is not much room for improvement left. What you can do improve user experience though is split that into a recursive function over a setTimeout, so that the browser doesn't freeze and you can display a nice loading animation. On Feb 5, 5:03 pm, James james.gp@gmail.com wrote: I need tips on optimizing a large DOM insert to lessen the freeze on the browser. Scenario: I receive a large amount of JSON 'data' through AJAX from a database (sorted the way I want viewed), and loop through them to add to a JS string, and insert that chunk of string into a tbody of a table. Then, I run a plug-in that formats the table (with pagination, etc.). Simplified sample code: var html = ''; $.each(data, function(i, row) { html += 'trtddata from json/td/tr';}); $(tbody).append(html); $(table).formatTable(); formatTable() requires that the table has to be completed before it can be executed. Is there any way I can optimize this better? I think I've read somewhere that making a string too long is not good, but I've also read that updating the DOM on each iteration is even
[jQuery] Re: Does it hurt to call functions that don't do anything on the page?
Checking for the presence of a relevant element should do: $(document).ready(function(){ if ( $('#categories').length ) ManageCategoriesClick(); if ( $('#ghosts').length ) HideByDefault(); if ( $('#split').length ) PrepareSplitForm(); }); Alternatively you could add a different class to the body of each page, then use this rather amusing construct: $(document).ready((function(){ var is = function(v){ return ++document.body.className.indexOf(v) }; return( is('categories') ? ManageCategoriesClick : is('hidebydefault') ? HideByDefault : is('form') ? PrepareSplitForm : is('advert') ? SetUpAdvertPopup : function(){} //nothing ); })()); (anonymous function returning the relevant function) In the second case only a single function can be returned, anyway I hope this can give you some ideas. - ricardo On Feb 7, 10:43 pm, Beau zar...@gmail.com wrote: So I have my document.ready function, looks something like this: $(document).ready(function(){ ManageCategoriesClick(); HideByDefault(); PrepareSplitForm(); SetUpAdvertPopup(); CheckAll(); CheckNone(); EditCategoryInPlace(); PreparePaneLinks(); PrepareToolTips(); }); Those functions all call things, but many are for specific pages. Does it slow the page down if they don't find the elements the functions call? What's the best way to call functions that are specific to a single page? -beau
[jQuery] Re: Optimize large DOM inserts
Hi Michael, Ouch. That's quite a difference. I thought about the join vs concatenate performance difference in IE, but didn't remember it could be that large. I take that one, I was being displiscent. cheers, - ricardo On Feb 6, 1:25 am, Michael Geary m...@mg.to wrote: ...there is not much room for improvement left. You just know that when you say that, someone will come along with a 20x-40x improvement. ;-) http://mg.to/test/loop1.html http://mg.to/test/loop2.html Try them in IE, where the performance is the worst and matters the most. On my test machine, the first one runs about 6.3 seconds and the second one about 0.13 seconds. -Mike From: Ricardo Tomasi Concatenating into a string is already much faster than appending in each loop, there is not much room for improvement left. What you can do improve user experience though is split that into a recursive function over a setTimeout, so that the browser doesn't freeze and you can display a nice loading animation. On Feb 5, 5:03 pm, James james.gp@gmail.com wrote: I need tips on optimizing a large DOM insert to lessen the freeze on the browser. Scenario: I receive a large amount of JSON 'data' through AJAX from a database (sorted the way I want viewed), and loop through them to add to a JS string, and insert that chunk of string into a tbody of a table. Then, I run a plug-in that formats the table (with pagination, etc.). Simplified sample code: var html = ''; $.each(data, function(i, row) { html += 'trtddata from json/td/tr';}); $(tbody).append(html); $(table).formatTable(); formatTable() requires that the table has to be completed before it can be executed. Is there any way I can optimize this better? I think I've read somewhere that making a string too long is not good, but I've also read that updating the DOM on each iteration is even worst. Any advice would be appreciated!
[jQuery] Re: Jquery plugin localisation nightmare
allRules appears to be a var (global?) inside the validationEngine function, not a property. Isn't it easier to just rewrite the whole validation js? On Feb 6, 12:46 pm, Karnius cedric.du...@gmail.com wrote: Hi guys, I got a plugin I want to do the localisation in french. I decided to go with a similar solution of the UI datepicker. Adding a french js and reparse my json object in french from there. But it just do not work and i don't have a clue how. Please help Live english version :http://www.position-relative.net/formValidator/test.html The core js : jQuery.fn.validationEngine = function(settings) { allRules = {required:{ // Add your regex rules here, you can take telephone as an example regex:none, alertText:* This field is required} } .. }; The French js: jQuery(function($){ $.validationEngine.allRules = {required:{ regex:none, alertText:* Ce champs est requis} } });
[jQuery] Re: Jquery plugin localisation nightmare
I think the point here is that the plugin is not his own, and it wasn't coded to support localisation. But I reckon that using that approach, if possible, would make maintenance easier. BTW, the jQuery validation plugin seems to support localization by default: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ - ricardo On Feb 6, 5:22 pm, Eric Garside gars...@gmail.com wrote: The easiest way to setup for localizations is to do local aliases for basically anything important. The idea is to have definition files (like localization.fr.js, localization.en.js) and abstracted variable names. For instance, you'd do things like: jQuery.fn[loc.validationEngine] = function(settings){ allRules = loc.allRules; } And in the localization files: // en.js loc = { validationEngine: 'validationEngine', allRules: {'required': {'regex': 'none', 'alertText': '* This field is required'}};} // fr.js loc = { validationEngine: 'frenchForValidationEngine', allRules:{'frForRequired': {'frForRegex': 'frForNone', 'frForAlertText': '* Ce champs est requis'}}; } Working like that will allow you to create a fully localized plugin. If you just want to localize some output strings, and not the actual function names, the same sort of methodology applies. It all depends on how you limit your scope. Also, sorry about the frForRequired stuff. I don't speak a lick of french. :( On Feb 6, 1:49 pm, Ricardo Tomasi ricardob...@gmail.com wrote: allRules appears to be a var (global?) inside the validationEngine function, not a property. Isn't it easier to just rewrite the whole validation js? On Feb 6, 12:46 pm, Karnius cedric.du...@gmail.com wrote: Hi guys, I got a plugin I want to do the localisation in french. I decided to go with a similar solution of the UI datepicker. Adding a french js and reparse my json object in french from there. But it just do not work and i don't have a clue how. Please help Live english version :http://www.position-relative.net/formValidator/test.html The core js : jQuery.fn.validationEngine = function(settings) { allRules = {required:{ // Add your regex rules here, you can take telephone as an example regex:none, alertText:* This field is required} } .. }; The French js: jQuery(function($){ $.validationEngine.allRules = {required:{ regex:none, alertText:* Ce champs est requis} } });
[jQuery] Re: Optimize large DOM inserts
Now I might have something useful to say! :) I remember this being discussed long ago on the 'replaceHTML' subject. Apparently using .innerHTML on an element that is not in the DOM is much faster (except for IE which is already fast). See here: http://blog.stevenlevithan.com/archives/faster-than-innerhtml http://www.bigdumbdev.com/2007/09/replacehtml-remove-insert-put-back-is.html cheers, - ricardo On Feb 6, 6:28 pm, James james.gp@gmail.com wrote: Big thanks for the optimization! It certainly did optimize the loop processing by several folds! However, for my case, I found that the ultimate bottleneck was the plug-in function that I was using that froze the browser the longest. The actual insert to the DOM took a bit of time also and did freeze the browser, but wasn't too bad even in IE6. By the way, do you have any tips on emptying a large amount of content in the DOM? Such as emptying that whole chunk of HTML that was inserted. That also freezes the browser also. I'm currently using $(el).empty(); and not sure if there's a more optimal solution. Thanks! On Feb 5, 5:25 pm, Michael Geary m...@mg.to wrote: ...there is not much room for improvement left. You just know that when you say that, someone will come along with a 20x-40x improvement. ;-) http://mg.to/test/loop1.html http://mg.to/test/loop2.html Try them in IE, where the performance is the worst and matters the most. On my test machine, the first one runs about 6.3 seconds and the second one about 0.13 seconds. -Mike From: Ricardo Tomasi Concatenating into a string is already much faster than appending in each loop, there is not much room for improvement left. What you can do improve user experience though is split that into a recursive function over a setTimeout, so that the browser doesn't freeze and you can display a nice loading animation. On Feb 5, 5:03 pm, James james.gp@gmail.com wrote: I need tips on optimizing a large DOM insert to lessen the freeze on the browser. Scenario: I receive a large amount of JSON 'data' through AJAX from a database (sorted the way I want viewed), and loop through them to add to a JS string, and insert that chunk of string into a tbody of a table. Then, I run a plug-in that formats the table (with pagination, etc.). Simplified sample code: var html = ''; $.each(data, function(i, row) { html += 'trtddata from json/td/tr';}); $(tbody).append(html); $(table).formatTable(); formatTable() requires that the table has to be completed before it can be executed. Is there any way I can optimize this better? I think I've read somewhere that making a string too long is not good, but I've also read that updating the DOM on each iteration is even worst. Any advice would be appreciated!
[jQuery] Re: how to change the iframe src
$('connectframe'+'iframe') should be $('#connectframe'+' iframe') (notice the whitespace) and so on.. On Feb 6, 7:34 pm, cindy ypu01...@yahoo.com wrote: Hi, what I want to do is to change iframe src, when click the tab. The click function is called, but the iframe src is not changed at all. Do you know what is wrong? Cindy !DOCTYPE HTML PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd; html xmlns=http://www.w3.org/1999/xhtml; head meta content=text/html; charset=iso-8859-1 http-equiv=Content- Type/ titleRAP Console/title link type=text/css media=screen rel=stylesheet href=clilib/ mainpage.css script src=jscripts/wizard/jquery-1.2.3.pack.js type=text/ javascript/script /head script var refreshTime=3; var summaryTab=1; var connectTab=2; var diagTab=3; var isSummaryInit= true; var isConnectInit=false; var isDiagInit=false; var mode=protype; var currentTab=summaryTab; function clickTab( tabName) { if(tabName==currentTab) return; if(tabName==summaryTab) { $('summaryframe'+'iframe').attr(src,http://www.google.com;); setFocus('summaryframe'); } else if(tabName==connectTab) { $('connectframe'+'iframe').attr(src,http://www.yahoo.com;); setFocus('connectframe'); } else if(tabName==diagTab) { $('diagframe'+'iframe').attr(src,http://www.yelp.com;); setFocus('diagframe'); } currentTab=tabName; }; $(document).ready(init); function init() { $('#Summary').bind('click',function(){clickTab(summaryTab)}); $('#Connectivity').bind('click',function(){clickTab(connectTab)}); $('#Diag').bind('click',function(){clickTab(diagTab)}); }; /script body div id=header div id=titleimg src=images/alogo.gif/div div id=header_logoimg src=images/ogo.gif/div /div div id=tab ul id=tab_ul class=up li id=SummarySummary/li li id=ConnectivityConnectivity/li li id=DiagDiagnostics/li /ul /div div id=global_content div id=statusConnection Status:/div div id=updateTime Last updated: 10:31:14 AM/div div id=refreshRefresh/div div id=gensupport Generate save support file/div /div div id=frame div id=summaryframe iframe width=100% height=100% frameborder=1/iframe /div div id =connectframe iframe width=100% height=100% frameborder=1/iframe /div div id =diagframe iframe width=100% height=100% frameborder=1/iframe /div /div /body /html
[jQuery] Re: Having problems getting index() and closest() to work
duplicate: http://groups.google.com/group/jquery-en/browse_thread/thread/1b8e73583661fa52/ec7d0d275d484f66?hl=en#ec7d0d275d484f66 On Feb 5, 9: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: How can I extract the index of an item based within a table?
Correction: you actually need the children collection to work out the index: var index = $(this).parent('tr').children().index(this); On Feb 5, 5:01 am, Ricardo Tomasi ricardob...@gmail.com wrote: var index = $(this).parent('tr').index(this); var quantity = $('.price_table th').eq(index).text(); alert( quantity ); On Feb 4, 9:45 pm, paulswansea sendtoswan...@hotmail.com wrote: Hi, I'm trying to write some jquery code so when i click on the relevent item price, it alerts me with the quantity of that item and also displays the content of the h2 header just before the relevant table, is there a way somehow of finding out the index of the 'td' which is clicked, and then extracting the quantity in the row above with the same index. also be able to grab the text from the h2 header before the table, so in effect, when i click on the '40p each' box within the first item table, it alerts me with the quantity being 1000, and also the h2 header of 'First Item Named here' Can someone please help!? Example : 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().mouseover( function(){ $(this).css('background-color','#F90'); $(this).css('cursor','hand'); $(this).css('cursor','pointer'); }).mouseout(function() { $(this).css('background-color','#EFEFEF'); $(this).css('cursor','default'); }).click( function() { alert('display quantity based upon the pricebox and also display the previous h2 heading'); } ); //]] /script
[jQuery] Re: Can i use selector to reach slice in jQuery 1.3?
It's much faster (and clearer) to use slice(): $('.button').slice(1,3); On Feb 5, 12:56 pm, Stephan Veigl stephan.ve...@gmail.com wrote: Hi that selector works just as it should. If you get other results in JQuery 1.2.6, then there was a bug in 1.2.6. What you ask for is: 1. give me every element of class = button {'.button'} == button1,...5 2. give me the element with index 1 = second element {:eq(1)} == button2 3. give me only the first 3 elements in the remaining selection {:lt(3)} == button2 what you described would be jQuery('.button:gt(1):lt(3)') by(e) Stephan 2009/2/5 Jackal jum...@gmail.com: I remember i can use the statement jQuery('.button:eq(1):lt(3)'); in jQuery 1.2.6. example: html body a href=# class=buttonbutton1/a a href=# class=buttonbutton2/a a href=# class=buttonbutton3/a a href=# class=buttonbutton4/a a href=# class=buttonbutton5/a /body html It returned matched button results from button2 to button4. But now it only returned button2 element in jQuery 1.3. So the selector statement like this can't chain filters??
[jQuery] Re: Optimize large DOM inserts
Concatenating into a string is already much faster than appending in each loop, there is not much room for improvement left. What you can do improve user experience though is split that into a recursive function over a setTimeout, so that the browser doesn't freeze and you can display a nice loading animation. On Feb 5, 5:03 pm, James james.gp@gmail.com wrote: I need tips on optimizing a large DOM insert to lessen the freeze on the browser. Scenario: I receive a large amount of JSON 'data' through AJAX from a database (sorted the way I want viewed), and loop through them to add to a JS string, and insert that chunk of string into a tbody of a table. Then, I run a plug-in that formats the table (with pagination, etc.). Simplified sample code: var html = ''; $.each(data, function(i, row) { html += 'trtddata from json/td/tr';}); $(tbody).append(html); $(table).formatTable(); formatTable() requires that the table has to be completed before it can be executed. Is there any way I can optimize this better? I think I've read somewhere that making a string too long is not good, but I've also read that updating the DOM on each iteration is even worst. Any advice would be appreciated!
[jQuery] Re: Optimize large DOM inserts
Concatenating into a string is already much faster than appending in each loop, there is not much room for improvement left. What you can do improve user experience though is split that into a recursive function over a setTimeout, so that the browser doesn't freeze and you can display a nice loading animation. James wrote: I need tips on optimizing a large DOM insert to lessen the freeze on the browser. Scenario: I receive a large amount of JSON 'data' through AJAX from a database (sorted the way I want viewed), and loop through them to add to a JS string, and insert that chunk of string into a tbody of a table. Then, I run a plug-in that formats the table (with pagination, etc.). Simplified sample code: var html = ''; $.each(data, function(i, row) { html += 'trtddata from json/td/tr'; }); $(tbody).append(html); $(table).formatTable(); formatTable() requires that the table has to be completed before it can be executed. Is there any way I can optimize this better? I think I've read somewhere that making a string too long is not good, but I've also read that updating the DOM on each iteration is even worst. Any advice would be appreciated!
[jQuery] Re: Scoping, Closure and $.post
renderTree: function(){ var tree = this; $.post(/Treeview?task=GET_NODEaction=DYNAMIC, {}, function() { tree.renderFolder(xml, 'foldersView'); }); }, On Feb 5, 5:54 pm, MoBel morrybel...@gmail.com wrote: I'm integrating prototype and jQuery together. I have a class that looks like this: var TreeView = function(){}; TreeView.prototype = { initialize: function() { this.view = 'Data management'; }, renderTree: function() { $.post(/Treeview?task=GET_NODEaction=DYNAMIC, {}, function () { this.renderFolder(xml, 'foldersView'); } ); }, renderFolder: function(xml, outputDiv) { // do some stuff } } var treeview = new TreeView(); Obviously this doesn't work because this does not refer to the my treeview instance of the TreeView object. I've also tried doing this with $.post $.post(/Treeview?task=GET_NODEaction=DYNAMIC, {}, function () { this.renderFolder(xml, 'foldersView'); }.bind(this) ); But that doesn't seem to help. So my question is, is there a way to get around this? Should I be writing my TreeView object in a different way?
[jQuery] Re: Is this list too busy? jQuery list for your time zone
I opted for the daily digest mail. I just take a look at the messages' subjects and choose what I want to read, works quite well, I don't waste any time. - ricardo On Feb 4, 10:16 am, boermans boerm...@gmail.com wrote: The time when I at least skimmed every message on this list in long gone. As jQuery becomes more and more popular, making your voice heard here gets increasingly difficult. Could time zone or locality be a useful way to divide the flow more effectively? Like local(ish) jQuery groups. What strategies do you use to make the most of the amazing resource this list is? I’m in Adelaide, South Australia GMT +9.5
[jQuery] Re: A couple of jQuery questions (recent converter from Prototype to jQuery)
Hi and welcome to jQuery :] A simple but not very effective way to do that is $ ('#myelement').parents('body').length, or, if you are sure you're dealing with a single element, a check for $('#myel')[0].parentNode would suffice. You can also implement this as a plug-in: jQuery.fn.inDOM = function(){ var d = false, m = (document.contains) ? function(){ return (d = document.contains(this)) } : function(){ return (d = !!(document.compareDocumentPosition (this) 16)) } this.each(m); return d; }; (there was a lengthy discussion about this at jquery-dev: http://groups.google.com/group/jquery-dev/browse_thread/thread/ac5ca8eaa64fe9f1/af83ebdd79de479a) jQuery has a few helper functions for strings, arrays, etc: http://docs.jquery.com/Utilities. I have yet to find something I can't do with it :) cheers, - ricardo On Feb 4, 9:29 am, Bisbo cappuccinof...@googlemail.com wrote: Hi there, I'm a recent converter from Prototype to jQuery and I've got a couple of questions. Firstly, if I am storing a jQuery object containing an element (var el = $('#myelement');) and then I subsequently remove that element ($ ('#myelement').remove()), how can I test my el variable to see if that element exists in the document or has been removed? I cannot simply test using the id of the element as I I'm storing tens of elements this way and it's not practical. It would appear that the jQuery object is still holding a reference to the removed element and hence any checks for it on the object return as okay. Secondly, I'm having some withdrawal symptoms from Prototype and I'm missing the many other functions such as it's String, Array, Object and even some of it's Element functions. I did think about using both libraries as the same time but that would be a hefty download. Are there any other options that anyone is using, perhaps some good plugins or other smaller libraries the do the job nicely? Many thanks, Michael
[jQuery] Re: getscript without parameters... an alernative?
Actually after the document has loaded, any function passed to $ (document).ready() will fire immediately. Also functions are called in the order they were added, so you can put it inside the getScript callback like this: $(document).ready(function(){ x = function(d){ alert(d) }; }); $.getScript('script.js', function(){ $(function(){ x('script loaded and DOM ready'); }); }); getScript() will be fired before DOM ready, then it's callback will add a function to $(doc).ready() which will execute after the function assignment. cheers, - ricardo On Feb 4, 12:53 pm, Eric Garside gars...@gmail.com wrote: Basically, the problem is this here: $(document).ready(function(){ You wrapped it inside an event that will only fire when the document throws its ready event. If you include the script after the page is loaded, regardless from where, th event will never fire. If you remove the $(document).ready(function(){ wrapper from script.js (called via getScript), it will work a lot easier. I've done a small snippet which does javascript backloading, which includes js files after the page has loaded. Worst case, it should still give you some idea of how to use a callback with getScript to fire a defined function within the script.js file. http://snipplr.com/view/10368/jquery-automatic-script-includer/ On Feb 4, 9:32 am, pere roca pero...@gmail.com wrote: hi Eric, I don't understand what you mean... the functions in script.js (called via getScript) work if I call $.getScript but I wanna call these functions from outside (after script is loaded), so I can pass some parameter to the functions that are inside script.js. $.getScript is not called when the page is loaded (I think that's what you mean). I'm firing it via Firebug console. thanks, Pere Eric Garside wrote: If you call $.getScript after your regular scripts are already loaded, domready will not fire again. On Feb 4, 8:16 am, pere roca pero...@gmail.com wrote: hi all, if I'm not wrong we cannot send parameters to a script called by getScript function; so, if we download or get the script and then we call a function inside the script, shouldn't it work? the function is there, now in our browser... but doesn't work. $.getScript('script.js'); x(); script.js: $(document).ready(function(){ //x function is declared as global x=function(datas) { alert(datas) }; }) Thanks!! -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com. -- View this message in context:http://www.nabble.com/getscript-without-parameters...-an-alernative--... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: a tag with good text popup (without title)
Look for 'tooltip' at plugins.jquery.com This is the first result on google: http://www.codylindley.com/blogstuff/js/jtip/ On Feb 4, 12:35 pm, Petty Pavlow pettypav...@googlemail.com wrote: Hi I would like to do some html (a tag) links.When u go with mouse on the top of this link it will pop up a box with (maybe with a photo or without) some good texts.I know i could do it with html (a tag title) but it seems like old kind. Thanks.
[jQuery] Re: having a problem with ' and strings
Replace all quotes inside your text variables with their correspondent HTML entities, then you should face no issues: titleFull = titleFull.replace(',#145;).replace('',quot;); I agree with Liam, it's best to use single quotes for the strings passed so you can use double quotes inside them. In XHTML all atribute values should use double quotes. - ricardo On Feb 4, 12:44 pm, dirk w dirkwendl...@googlemail.com wrote: hello jquery community, i am getting some strings from a page i don't have influence on. i just append those to elements (thanks to jquery this works like a charm!): $(#searchResultList).append(li class='searchResultEntry'id=' + videoId + ' title=' + titleFull + ( + minutes + : + seconds + )'img src=' + thumbnailUrl + ' class='thumbnail' alt=' + titleFull + ( + minutes + : + seconds + )'//li); my problem is: sometimes the variable title contains a ' in the string, like doesn't that look funny... in this case my output get's completely messed up. is there a more reliable way to use ' and ? any ideas how i could prevent ' to crack this up? thanks in advance dirk
[jQuery] Re: Change subdomain on same page...
The usual way that's done is via the URL hash: http://adamkobrin.com/#about location.hash == '#about' - ricardo On Feb 4, 3:50 pm, atomk akob...@adamkobrin.com wrote: I have different subdomains pointing to the same file on my server - simple enough. What I'd like to do is essentially reverse that: Can the same file redirect to different subdomains? For example:http://adamkobrin.com When you click on any of the top 4 links, different content is loaded, but you remain on the same page with (hopefully) nice smooth transitions - the url remains unchanged. I'm looking for a client-side way to change the subdomain in the location bar based on each link, making it possible for the user to bookmark each page differently, without compromising my smooth transitions by loading a new page... Make sense? Possible? Thanks!
[jQuery] Re: having a problem with ' and strings
My friend Mauricio Samy pointed out a mistake I made: attributes enclosed in single quotes are actually valid in XHTML/XML. I'm used to single quotes as a standard for JS, and double ones for XHTML, makes code clearer in both. cheers, - ricardo On Feb 4, 3:56 pm, Ricardo Tomasi ricardob...@gmail.com wrote: Replace all quotes inside your text variables with their correspondent HTML entities, then you should face no issues: titleFull = titleFull.replace(',#145;).replace('',quot;); I agree with Liam, it's best to use single quotes for the strings passed so you can use double quotes inside them. In XHTML all atribute values should use double quotes. - ricardo On Feb 4, 12:44 pm, dirk w dirkwendl...@googlemail.com wrote: hello jquery community, i am getting some strings from a page i don't have influence on. i just append those to elements (thanks to jquery this works like a charm!): $(#searchResultList).append(li class='searchResultEntry'id=' + videoId + ' title=' + titleFull + ( + minutes + : + seconds + )'img src=' + thumbnailUrl + ' class='thumbnail' alt=' + titleFull + ( + minutes + : + seconds + )'//li); my problem is: sometimes the variable title contains a ' in the string, like doesn't that look funny... in this case my output get's completely messed up. is there a more reliable way to use ' and ? any ideas how i could prevent ' to crack this up? thanks in advance dirk
[jQuery] Re: stilted animation in all browsers except Chrome Opera
The page doesn't load at all in IE7: Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in E: \domains\a\antoniocaniparoli.co.uk\user\htdocs\wip1\antonio.php on line 4 and other errors. On Feb 4, 3:15 pm, Barney barney.carr...@gmail.com wrote: Hi all! Having a great adventure of my first jQuery website — for ages I'd been telling myself I should just get better at javascript, but I'd been following the development of Sizzle and thought, right, this is great! http://antoniocaniparoli.co.uk/wip1 I am having a bit of a headache with cross-browser compatibilities though. My script has two purposes: positioning and sizing the various elements that constitute a photo gallery, and animating transitions between images. As far as the positioning and sizing is concerned, every major browser (Chrome, FF, IE, Opera, Safari latest stable releases) processes the maths/DOM metrics differently. I expected this out of IE, but it's incredibly distressing that the 'standardised' rendering engines differ so wildly in their interpretation of the same data. If anybody has any insights into this, I'd be very interested. For the moment, FF behaves as I believe everything else should in this matter (apart from:...) My biggest worry is to do with jQuery animation though. The gallery's 'sliding' mechanism — outside of the issue of the bad parsed maths — seems to 'skip' half of the animation in IE, FF Safari. In Chrome and Opera it operates completely smoothly (but doesn't slide to the right location). The animation code is on lines 71-78 ofhttp://antoniocaniparoli.co.uk/wip1/antonio.js: $('#gallery p a:first-child').click(function() { galLeft = parseInt($('#gallery').css('left'))+(vpX-294)/2+'px'; $('#gallery').animate({left: galLeft}, 1500); }) $('#gallery p a:last-child').click(function() { galLeft = parseInt($('#gallery').css('left'))-(vpX-294)/2+'px'; $('#gallery').animate({left: galLeft}, 1500); }) The equation takes the viewport's width and subtracts the offsetWidth of the non-gallery content on the left to give the gallery width — and in theory every item in the gallery has just enough left and right padding to fill the gallery's visible area. Again, all the metrics work in FF. So the real issue is why that animation is stilted in most browsers. Any ideas? NB: People might think this has something to do with the easing plugin I've got in there. I have commented out all reference to it to avoid ambiguity.
[jQuery] Re: .eq(variable) strange behaviour
menuLoading(currentMenuItem,menuLength) -- with this you're calling the function instantly, not passing it as a callback. You can't pass parameters to the callback this way, use local vars instead. Also you should increase the currentMenu var only after you've chosen the current one. $('.menu li').eq(currentMenuItem) .animate({opacity : 1},3000) .animate({opacity : 0.6}, 2000, function(){ menuLoading(++currentMenuItem, menuLength); }); On Feb 4, 1:04 pm, antoinepairet antoinepai...@gmail.com wrote: Hi! I'm trying to have a menu for which each item loads after the preceding one is loaded. For this purpose, I wrote the following function: function menuLoading(currentMenuItem,menuLength){ console.log(currentMenuItem); currentMenuItem++; if(currentMenuItem=menuLength){ $('.menu li').eq(currentMenuItem).animate({opacity : 1}, 3000).animate({opacity : 0.6}, 2000 ,menuLoading (currentMenuItem,menuLength)); } } Initially, the li items of the menu are set at opacity 0. With the function I modify the opacity. I'd like every item to start loading when the previous one is shown. However, all the elements appear at the same time. If I replace eq(currentMenuItem) by eq(1), only the first is shown. How could I make it? Thanks a lot! ps: $('.menu li:eq(' + currentMenuItem + ')').animate({opacity : 1}, 3000).animate({opacity : 0.6}, 2000 ,menuLoading (currentMenuItem,menuLength)); works like the code above bu does not do what is expected
[jQuery] Re: setting focus to the first empty field
$('[value=]') seems to be broken in 1.3.1 (fixed in the nightlies, see http://dev.jquery.com/ticket/3990), so that would be $('form input[value=]:first').focus(); cheers, - ricardo On Feb 4, 7:38 pm, Klaus Hartl klaus.ha...@googlemail.com wrote: $('form input[value=]:first').focus(); --Klaus On 4 Feb., 20:57, Massiverse august.massive...@gmail.com wrote: Hello I'm a newbie, here's what I need to do (searched the forums first but couldn't find the answer). 1. Search form for an empty input field. 2. If an empty field exists, set the focus on the field. 3. If no empty fields exist, do nothing. Thanks, August
[jQuery] Re: How can I extract the index of an item based within a table?
var index = $(this).parent('tr').index(this); var quantity = $('.price_table th').eq(index).text(); alert( quantity ); On Feb 4, 9:45 pm, paulswansea sendtoswan...@hotmail.com wrote: Hi, I'm trying to write some jquery code so when i click on the relevent item price, it alerts me with the quantity of that item and also displays the content of the h2 header just before the relevant table, is there a way somehow of finding out the index of the 'td' which is clicked, and then extracting the quantity in the row above with the same index. also be able to grab the text from the h2 header before the table, so in effect, when i click on the '40p each' box within the first item table, it alerts me with the quantity being 1000, and also the h2 header of 'First Item Named here' Can someone please help!? Example : 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().mouseover( function(){ $(this).css('background-color','#F90'); $(this).css('cursor','hand'); $(this).css('cursor','pointer'); }).mouseout(function() { $(this).css('background-color','#EFEFEF'); $(this).css('cursor','default'); }).click( function() { alert('display quantity based upon the pricebox and also display the previous h2 heading'); } ); //]] /script
[jQuery] Re: Jquery adds its own tags to divs???
You see them in IE Developer Toolbar, right? These are unique identifiers for elements, serves the data() function and others. On Feb 4, 11:57 pm, Andy789 e...@abcstudio.com.au wrote: Hi All, I cannot understabd why jquery adds these tags to my divs - something like: jquery1233798431484=2 jquery1233798241359=null what is this?
[jQuery] Re: about :not(:last)
It's not a bug, it's the documented behavior: :first Matches the first selected element. http://docs.jquery.com/Selectors/first Let's go through it again. When you call $(this).parents() you get this array of elements: [0] dd [1] dl [2] dd [3] dl [4] dd [5] dl Which are all the element's parents, in order. That's the collection you're dealing with. Now, :first refers to the first element ([0]) in that set, and only that, it has no other meaning. So dl:first will match nothing, as no dl is the ':first' element. dd:first will match the same as dd:eq(0) or simply :first. You have to take in account that the pseudo-selectors are a set of defined filters, there is no 'semantic' in them. Maybe this could be improved, but that would be a change in syntax, not a 'bug correction'. Again, that's what slice() is for, slicing the array of elements as you wish. cheers, - ricardo On Feb 3, 12:28 am, Garito gar...@gmail.com wrote: Sorry, Ricardo, but this isn't so much logic, isn't it? When I see dl:not(:first) I read give me all dl except the first one Imagine this was a mathematics expression We read from left to right: first filter all dl's with the result exclude the first one I can understand a bug but it's dificult to me to understand your explanation about this issue even when I test the code with the iPhone safari (on Wednesday I could try it with IE to see the dl supposed, on FF or Safari don't appears, problem you point) I don't know who decides (at jQuery) what is a bug and what isn't but in my opinion this is one of them If jQuery people wants to correct them, ok If not ok but jQuery will have it's first point to leave it as soon as a better library appears I can do anything more that change my code to solve this jQuery bug but this don't change the fact that there is a bug at jQuery Thanks On 3 feb, 02:32, Ricardo Tomasi ricardob...@gmail.com wrote: I haven't seen your page, but I know that styling dd and dt elements for IE is a pain. And the invalid mark-up might bring you problems with different browsers. The usual behavior for invalid nesting is to close the offended tag to make it valid, so this dl dt div/div /dt dd/ /dl would become dl dt /dt /dl div/div dl dd/ /dl Firefox is surprisingly tolerant in this case, but I haven't tested elsewhere. Valid mark-up is a safe harbour specially with regards to DOM manipulation. That aside, I found the issue, it's actually quite simple. this.parents('dl:not(:first)') let's see what's happening: - first, this gets you all the parents() for 'root'. Without any filtering, that would be DD, DL, DD, DL etc. - then you ask it to filter the elements which are 'DL's AND are not the first match. Here's the catch: :first refers to the first match in the set, which is a DD element, not a DL one. The DL is never going to be the first match. :first will always filter according to the current set, before any other expressions in the same call are evaluated. So what you need to do is filter the parents set again: var slots = $(this).parents('dl').filter(':not(:first)').map(function () { return $(.Texto:first, $(this)).text(); } Or use slice() instead as I posted before, that will be much faster as you're just slicing the array without dealing with elements/selectors. var slots = $(this).parents('dl').slice(1).map(function() { return $(.Texto:first, $(this)).text(); } cheers, - ricardo On Feb 2, 11:35 am, Garito gar...@gmail.com wrote: Sorry Ricardo but you say the problem is the dt element? With this markup I can do what I need in terms of css With the css I put the divs inside the dt element to put a label, the icon and the other div to switch between visible/non visible dd How do you think I could put my markup to avoid this problem? I don't like your suggest because one of the main reasons to change from prototype to jquery was the css's selectors and they power I thinks this is a jquery's bug, isn't it? On 2 feb, 10:02, Ricardo Tomasi ricardob...@gmail.com wrote: Ah that's quite confusing mark-up. A dt element can only contain inline elements, certainly not divs and other definition lists. Nested definition lists make no sense! I couldn't find the problem. Try $(this).parents('dl').slice(1) or $(this).parents('dl').slice (0,-1), that will probably work. cheers, - ricardo On Feb 1, 10:57 pm,Garitogar...@gmail.com wrote: Gracias, Ricardo! I change the code with the complete test case for my issue Sorry for the identation but the original code is generated and I copy/ paste with firebug If I'm not wrong, with the selector 'dl:not(:last)' SITE dl is incorrect in the returned list because is the last dl (if not 'dl' will be equal to 'dl:not(:last)') am I confused or there is a bug
[jQuery] Re: How to enlarge size proportionally
$('#anim').animate({marginLeft: '-=50', width: '+=100'}); or $('#anim').css('position', 'relative').animate({left -50, width: '+=100'}); On Feb 3, 1:11 pm, Eric Garside gars...@gmail.com wrote: Hmm. Lets say you need it to grow 100px. Would: $('#anim').animate({paddingLeft: 50, width: 50}); work? It's hard to say what would help without a better idea of what the element you want to grow looks like. On Feb 3, 9:34 am, David .Wu chan1...@gmail.com wrote: animate function can change object's size by control css, such as width and height, if if we want to increase the width, the width increased to right - how to do it like below - -
[jQuery] Re: Performance suggestion: Use object hash instead of regexp
I think this should be posted at jquery-dev. There is no significant difference between the hash and switch options, less than 10ms for 200.000 iterations (FF3). But both offer a solid speed improvement over a simple regex in the case posted when dealing with hundreds of calls. That could be important in case offset() is being used in an animation function or similar. On Feb 3, 6:05 pm, jay jay.ab...@gmail.com wrote: I imagine a switch is the same speed as a hash (switches generally evaluate to a hash). Using a trie structure could be faster than regex in some circumstances I imagine: http://en.wikipedia.org/wiki/Trie On Feb 3, 12:45 pm, Eric Garside gars...@gmail.com wrote: In that case, wouldn't a switch statement have even less overhead than creating an object to check everytime? I'd think switch(tag){case 'body':case 'html': /* ... */ break;} would be an even faster solution, no? On Feb 3, 12:39 pm, George Adamson george.adam...@softwareunity.com wrote: Absolutely, it is very very limited. So this technique is only suited to the type of regex's that I quoted, like the one used internally by jquery to test for body or html tags only, or to test for t(able|d|h) only. Particulalry when used inside a loop. For parsing a selector we still need regex. On Feb 3, 3:16 pm, Eric Garside gars...@gmail.com wrote: Using a hash I can see for some situations, but unless you can figure out a way (and I'd be super interested if you could) to do complex cascade parsing without regex, your method seems like double the work of rewriting with no benefits towards maintainability and a minor speed increase for only certain tags.- Hide quoted text - - Show quoted text -
[jQuery] Re: pass variable from button to jquery
Where in your code is that ID? Is it an attribute of an element or just text inside #contentcolumn ? On Feb 1, 7:52 pm, ktpmm5 ka...@steppingstonez.com wrote: I am displaying a bunch of data from a mysql database, shown below. After the data is displayed, I put a button for each line of data. When a user clicks the button, I call the load function. I am trying to figure out how to pass the id (received from the mysql db) for each particular record to the jquery load function. Here is my code: [code] html while($row = mysql_fetch_array($result)) { echo $row['day']; echo /tdtd; button class=volunteer value=volunteerVolunteer/button . js $(#contentcolumn).load(popup.php?gameno=?); [/code] How can I pass the id (received from mysqldb) via the Volunteer button? I'll then use this to lookup and display more data... -- View this message in context:http://www.nabble.com/pass-variable-from-button-to-jquery-tp21780863s... Sent from the jQuery General Discussion mailing list archive at Nabble.com.
[jQuery] Re: about :not(:last)
Ah that's quite confusing mark-up. A dt element can only contain inline elements, certainly not divs and other definition lists. Nested definition lists make no sense! I couldn't find the problem. Try $(this).parents('dl').slice(1) or $(this).parents('dl').slice (0,-1), that will probably work. cheers, - ricardo On Feb 1, 10:57 pm, Garito gar...@gmail.com wrote: Gracias, Ricardo! I change the code with the complete test case for my issue Sorry for the identation but the original code is generated and I copy/ paste with firebug If I'm not wrong, with the selector 'dl:not(:last)' SITE dl is incorrect in the returned list because is the last dl (if not 'dl' will be equal to 'dl:not(:last)') am I confused or there is a bug? Thanks! On 1 feb, 21:07, Ricardo Tomasi ricardob...@gmail.com wrote: http://jquery.nodnod.net/cases/85 Parece ok aqui. Pode ser alguma outra coisa na tua página, não dá pra saber sem ver o html. Seems to work fine here. Could you post a complete test page showing this issue? - ricardo On Feb 1, 1:25 pm,Garitogar...@gmail.com wrote: Hi! Please, consider this code: $.fn.url2 = function(absoluta) { var slots = $(this).parents('dl:not(:last)').map(function() { return $(.Texto:first, $(this)).text(); }); var slots2 = $(this).parents('dl').map(function() { return $(.Texto:first, $(this)).text(); }); return slots.get().join(/) + ' -- ' + slots2.get().join(/); }; The funny thing of this code is that slots and slots2 have the same items Could you point me why slots put the last dl? I suppose that dl:not(:last) retrieves all the parents except the last one but this don't work Thanks!
[jQuery] Re: block on body onload, unblock on at the end of $(document).ready
the 'onload' event actually fires after document ready - that's the reason doc ready exists! What you want is to block *on* doc ready, and unblock after your ajax stuff is finished. As ajax is asynchronous, you'll have to keep track of every call to know when everything is done. $(document).ready(function(){ $.blockUI({ message: null }); var count = 0, ajaxCount = function(){ count++; if (count == 5) //total number of ajax calls $.unblockUI(); }); $('xis').load('bla.py', function(){ //bla bla ajaxCount(); }); $.ajax({ etc etc, success: function(){ //blablabla etc etc ajaxCount(); }); ... and so on.. }); On Feb 1, 10:57 pm, cambazz camb...@gmail.com wrote: Hello, I would like to blockUI on body onload like: body onload=$.blockUI({ message: null }); and when document ready finishes unblock, but unfortunately i can not unblock it if I put blockUI on onload of body. My page makes few ajax calls and some processing on document ready, and i want to blockUI until page finishes loading completely. Is there a solution, or a workaround? Best.
[jQuery] Re: access table row[y] cell[x]
You can also write your own methods, that's the beauty of jQuery: jQuery.fn.getCell = function(x,y){ return jQuery( this[0].rows[y].cells[x] ); }; $('#myTable').getCell(5,1).html('New content'); - ricardo On Feb 2, 7:25 pm, Michael Geary m...@mg.to wrote: That didn't work because .html is a method, not a property you can set. This would have a better chance of working: $('#myTable tr:eq(4) td:eq(3)').html( 'new text' ); But what was wrong with your original code? It looked fine to me (except for the var oCell = part - that doesn't look right, since it sounds like you're expecting oCell to be a reference to the column element when it will actually be the text string). And I suspect that the integer row and column numbers will probably not be hard coded numbers in the actual code, but variables, right? So your actual jQuery code might be something more like: $( '#myTable tr:eq(' + y + ') td:eq(' + x + ')' ).html( text ); Instead of all that, you could use jQuery just as a shortcut for the document.getElementById() call and keep the rest of your code. And since you're probably doing a number of jQuery and DOM operations on the table, let's cache the table's jQuery object and DOM element in a pair of variables: var $myTable = $('#myTable'), myTable = $myTable[0]; // ...and later... myTable.rows[y].cells[x].innerHTML = text; This is both simpler and cleaner than the :eq() selector, and it's likely to be much faster too. -Mike From: JAS Well I tried: $(#myTable tr:eq(4) td:eq(3)).html = new text; and, while it gave no error, it also produced no result. Any other ideas? JAS On Feb 2, 5:15 pm, ksun kavi.sunda...@gmail.com wrote: 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: jQuery + iPhone, improving element animations
The best approach for the iPhone would be to use CSS3 animations, they run much smoother. Also, have you seen jQuery touch? Might be useful: http://www.manifestinteractive.com/iphone/touch/ On Feb 2, 7:04 pm, persilj sma...@gmail.com wrote: I tend to create versions for different platforms and frameworks from my Nutrition tactician -webservice. It's basically an alternative interface to USDA-database, which contain nutritional values for lots of different foods. This time I wanted to make a version, which is especially crafted for iPhone-use. You may try it with Firefox or Safari, too. At the moment of writing IE gives a script-error, but I'll fix those minor bugs later. http://datacalmers.hoito.org/iphonent/ However, I'm a bit disappointed at the sluggish movement of animated elements, but this seems to be problem in all of the webapplications for iPhone, which scroll an element from side to side. Or am I incorrect here? Should I try something else than just something like this: $('#nutritiondetails').animate({left : '100%', opacity : 'toggle'}, 'slow');
[jQuery] Re: callback for append function?
Take notice that the image's load event doesn't always fire in IE. You have to use .bind('readystatechange load', loaded) function loaded(){ if (this.complete) // or if (this.readyState == 'complete') //do stuff to guarantee that the function will be called (the .complete property is always true on FF, and it doesnt fire readystatechange for images). cheers, - ricardo On Feb 2, 4:17 pm, Stephan Veigl stephan.ve...@gmail.com wrote: You can make a function you call every time an image has been loaded and update a counter in this function. Once the counter reaches the number if images you have on your page, you know that all images where loaded. see:http://jsbin.com/ofici/edit by(e) Stephan 2009/2/2 Liam Potter radioactiv...@gmail.com: can you please not delete the quoted message, as I have no idea what you just thanked someone for now. lhwpa...@googlemail.com wrote: great! thanks for that! one last question. is it possible to fire a function when the last of 5 images is loaded ?
[jQuery] Re: simple jQuery img src Question
Small correction: it should be bind('readystatechange'.. as jQuery adds the 'on' prefix by itself. cheers, - ricardo On Jan 22, 3:25 am, LoicDuros loic.du...@gmail.com wrote: Thanks everyone for your help. many different ways of doing it... I'll try each of them until something works! THanks! On Jan 21, 11:35 pm, Ricardo Tomasi ricardob...@gmail.com wrote: A cross-browser way of doing that: $('img').fadeOut(500, function(){ $(this).attr('src',newsrc).bind('onreadystatechangeload', function() { if (this.complete) $(this).fadeIn(1000); }); }); http://jsbin.com/urikuhttp://jsbin.com/uriku/edit On Jan 21, 7:30 pm, Balazs Endresz balazs.endr...@gmail.com wrote: Also, see this discussion about using theloadevent with images:http://groups.google.com/group/jquery-dev/browse_thread/thread/24b107... On Jan 21, 8:55 pm, Bohdan Ganicky bohdan.gani...@gmail.com wrote: Fixed braces: $('#image').fadeOut(500, function() { $(this).attr('src','images/'+newImg).load(function() { $(this).fadeIn(1000); }); }); -- Bohdan On Jan 21, 8:54 pm, Bohdan Ganicky bohdan.gani...@gmail.com wrote: In theory it would be something like this: $('#image').fadeOut(500, function() { $(this).attr('src','images/'+newImg).load(function() { $(this).fadeIn(1000); }); } ...but I'm not at all sure if the load() captures the src attribute change like that. -- Bohdan On Jan 21, 7:54 pm, LoicDuros loic.du...@gmail.com wrote: Hi, I'm new to JQuery and used to use Scriptaculous. I would like to make the following: A function to fade out animage, then change the src of theimage, and once the new src is loaded, to fade in theimageback (so that it's fading in with the newimageloaded). Here is how I did it using Scriptaculous, however, the site will now use jQuery and so I have to reproduce the same thing with it - is there such a thing as observe in jQuery: function navAction(newImg) { new Effect.Fade('image', {duration:0.5, afterFinish:function(){ document.getElementById('image').src = 'images/' + newImg; $(document.getElementById(image)).observe('load', display); } }); } function display(event){ new Effect.Appear('image', {duration:1}); }
[jQuery] Re: Can't select an id containing '/' ?
You have to escape special characters with a double backslash: $('#\\/about\\/') On Feb 2, 4:35 am, starmonkey scott.macl...@gmail.com wrote: Using jQuery 1.2.6, it would seem that any id containing a forward slash cannot be selected using jQuery's syntax: div id=blahtesting blah/div div id=/about/testing about/div div id=/about2testing about2/div div id=about3/testing about3/div $('#/about/') - jQuery obj with length=0 returned $('#/about2') - jQuery obj with length=0 returned $('#about3/') - jQuery obj with length=0 returned $('#blah') - works Just wondering if this is a bug, or me using a html id attribute in a manner not allowed? cheers, SM
[jQuery] Re: How to get html string including the selected element
Try this: http://yelotofu.com/2008/08/jquery-outerhtml/ On Feb 2, 7:13 am, Andy789 e...@abcstudio.com.au wrote: Hi All, I need to get html for a dom structure like this: div id=test div id=test2something/div img ../ /div if I use $('div#test').html(); it generates its innerHTML excluding div id=test How an I get the whole structure including id test? thanks
[jQuery] Re: How to get html string including the selected element
Oops, wrong URL. This is the right one: http://plugins.jquery.com/project/outerhtml On Feb 2, 9:59 pm, Ricardo Tomasi ricardob...@gmail.com wrote: Try this: http://yelotofu.com/2008/08/jquery-outerhtml/ On Feb 2, 7:13 am, Andy789 e...@abcstudio.com.au wrote: Hi All, I need to get html for a dom structure like this: div id=test div id=test2something/div img ../ /div if I use $('div#test').html(); it generates its innerHTML excluding div id=test How an I get the whole structure including id test? thanks