[jQuery] Re: Scrolling Problem
Thanks Nathan, it works as expected ! Great help ! On 20 fév, 21:34, Nathan Klatt wrote: > On Sat, Feb 20, 2010 at 9:13 AM, macgyver47 wrote: > > div1 class="post" > > div class="title" > > > > div10 id="post" > > div class="title" > > I am trying: clicking on div#title belonging to div1 scrolls to > > div#title belonging to div2 and so on > > $().ready(function() { > $(".title").click(function() { > var thisPost = $(this).parent(); > var nextPost = thisPost.next(".post"); > if ( ! nextPost.length ) nextPost = thisPost.parent().find(".post"); > var positionOfNextTitle = nextPost.find(".title").position(); // or > offset() > window.scrollTo(positionOfNextTitle.left, positionOfNextTitle.top); > }); > > }); > > http://jsbin.com/adoti/edit > > Nathan
[jQuery] Scrolling Problem
Hi I have div1 class="post" div class="title" div2 class="post" div class="title" div3 id="post" div class="title" div10 id="post" div class="title" I am trying: clicking on div#title belonging to div1 scrolls to div#title belonging to div2 and so on to cut a long story short clicking on div#title scrolls to the next div#title and so on I have tried and not succeded so far Any help will be very much appreciated jean
[jQuery] Re: Automatic scrolling
Thanks for advice but your answer doesn't help as you cannot generate a click on "a" link with jQuery I have used this solution on other pages and it works great but in this particular case: I would like visitor to be scrolled automatically to particular spot on page depending on radio button being clicked I am looking for something like: jQuery('input#oui').click(function(){ jQuery('div#reponse1').show('slow'); jQuery('div.postpop').show('slow'); jQuery('div#reponse2').hide('fast'); jQuery('div#reponse3').hide('fast'); jQuery(SCROLLTO-automatically-to-paragraph1); }); Still trying to find answer Jean On 4 jan, 16:45, Paul Hutson wrote: > > Thanks for help > > This should do what you want (well, it's an example, but I'm sure you > can pull out the bits you need) > :http://www.position-relative.net/creation/anchor/ > > It'll smooth scroll to the right location for you... :) > > (we've also used it on the help for Outer Empires, > here...http://gameview.outer-empires.com/Info/Newbie.asp) > > HTHs, > Paul Hutson
[jQuery] Automatic scrolling
I am using 3 radio buttons ... user clicks on radio button 1 called input#oui jQuery('input#oui').click(function(){ jQuery('div#reponse1').show('slow'); jQuery('div.postpop').show('slow'); jQuery('div#reponse2').hide('fast'); jQuery('div#reponse3').hide('fast'); }); This works perfectly well but as size of text on page changes quite a bit I need to send reader to either top of page automatically or better to a certain div How can I achieve this as simulating a click on a link doesn't work using locallScroll as I do for top of page or botton of page Thanks for help
[jQuery] Re: jQuery each problem
I agree with you $(this).val() = 'yes'; means nothing $(this).val() == 'yes' or $(this).val() === 'yes' returned nothing var yes_or_no=jQuery(this).attr("value"); returned what I was looking for Thank you for great help Jean from France On 15 mar, 21:35, Josh Powell wrote: > Glad I could help. That's an interesting thing you ran into, first, i > assume that instead of > $(this).val() = 'yes'; > > you meant > > $(this).val() == 'yes' or $(this).val() === 'yes' > > because the first one meant you are trying to store 'yes' in $ > (this).val()... which wouldn't work anyway. Actually before > theorizing any further, did you actually test the first or second > versions of that statement above? > > On Mar 15, 11:25 am, macgyver47 wrote: > > > What works is > > var yes_or_no=jQuery(this).attr("value"); > > if(yes_or_no=="yes"){ > > do something} > > > else > > { > > do something else} > > > Thanks for helping all the way to a fine solution > > > On 15 mar, 15:10, macgyver47 wrote: > > > > Unfortunatly it doesn't work > > > if ($(this).val() = 'yes') > > > returns nothing > > > $(this).val() returns "on" no matter if you click on button Yes or > > > button No > > > I have been ckecking jquery doc the best I could and cannot find > > > answer to my question: how to I know if user clicked on button Yes or > > > button No > > > Any other ideas ??? > > > Thanks in advance > > > Jean from France > > > On 14 mar, 17:54, Josh Powell wrote: > > > > > $(this).is("eq[0]") > > > > > will not work because, is looks at the list of jquery objects that $ > > > > (this) returns. Which is just one object. > > > > > try giving the input a value of yes or no and doing > > > > > if ($(this).val() === 'yes') > > > > > On Mar 14, 8:51 am, macgyver47 wrote: > > > > > > One more question if this is not abusing your time > > > > > Structure ofeachquestion: > > > > > > > > > onclick='q1=1'>Yes > > > > > No > > > > > > > > > > jQuery('.choix').click(function(e) { > > > > > $(this).parent().hide();}); > > > > > > as expected your answer hides the content of the question as expected > > > > > How can I know if first (yes) or second (no) button was clicked > > > > > I tried introducing after $(this).parent().hide(); something like > > > > > if (jQuery(this).is(":eq[0]")) { > > > > > do something > > > > > } > > > > > else > > > > > { > > > > > do something} > > > > > > but it doesn't work ! > > > > > Any ideas ? > > > > > Thanks for help > > > > > Jean from France > > > > > On Mar 14, 9:49 am, macgyver47 wrote: > > > > > > > Thank you very much for a great answer which nearly solved my > > > > > > question in a very elegant way, I have even discovered in studying > > > > > > selectors a little more thouroughly ( jquery doc) that you can use > > > > > > jQuery('.choix').click(function(e) { > > > > > > $(this).parent().parent().hide(); > > > > > > and it will go 2 levels up instead of one as described in you > > > > > > solution > > > > > > Thanks to great people like you Josh I am learning ( slowly) > > > > > > Many thanks > > > > > > Jean from France > > > > > > > On 14 mar, 08:27, Josh Powell wrote: > > > > > > > > Yes, forget about using ID's in this way. That's something you > > > > > > > had to > > > > > > > do before using jQuery. Think about how your HTML is structured > > > > > > > and > > > > > > > things are named/classed and the order they are in. Take > > > > > > > advantage of > > > > > > > how easy it is to traverse the DOM with jQuery. If yo uhave > > > > > > > > > > > > > > > link 1 > > > > > > > Description > > > > > > > > > > > > > > > > > > > > > > link 2 > >
[jQuery] Re: jQuery each problem
What works is var yes_or_no=jQuery(this).attr("value"); if(yes_or_no=="yes"){ do something } else { do something else } Thanks for helping all the way to a fine solution On 15 mar, 15:10, macgyver47 wrote: > Unfortunatly it doesn't work > if ($(this).val() = 'yes') > returns nothing > $(this).val() returns "on" no matter if you click on button Yes or > button No > I have been ckecking jquery doc the best I could and cannot find > answer to my question: how to I know if user clicked on button Yes or > button No > Any other ideas ??? > Thanks in advance > Jean from France > On 14 mar, 17:54, Josh Powell wrote: > > > $(this).is("eq[0]") > > > will not work because, is looks at the list of jquery objects that $ > > (this) returns. Which is just one object. > > > try giving the input a value of yes or no and doing > > > if ($(this).val() === 'yes') > > > On Mar 14, 8:51 am, macgyver47 wrote: > > > > One more question if this is not abusing your time > > > Structure of each question: > > > > > onclick='q1=1'>Yes > > > No > > > > > > jQuery('.choix').click(function(e) { > > > $(this).parent().hide();}); > > > > as expected your answer hides the content of the question as expected > > > How can I know if first (yes) or second (no) button was clicked > > > I tried introducing after $(this).parent().hide(); something like > > > if (jQuery(this).is(":eq[0]")) { > > > do something > > > } > > > else > > > { > > > do something} > > > > but it doesn't work ! > > > Any ideas ? > > > Thanks for help > > > Jean from France > > > On Mar 14, 9:49 am, macgyver47 wrote: > > > > > Thank you very much for a great answer which nearly solved my > > > > question in a very elegant way, I have even discovered in studying > > > > selectors a little more thouroughly ( jquery doc) that you can use > > > > jQuery('.choix').click(function(e) { > > > > $(this).parent().parent().hide(); > > > > and it will go 2 levels up instead of one as described in you solution > > > > Thanks to great people like you Josh I am learning ( slowly) > > > > Many thanks > > > > Jean from France > > > > > On 14 mar, 08:27, Josh Powell wrote: > > > > > > Yes, forget about using ID's in this way. That's something you had to > > > > > do before using jQuery. Think about how your HTML is structured and > > > > > things are named/classed and the order they are in. Take advantage of > > > > > how easy it is to traverse the DOM with jQuery. If yo uhave > > > > > > > > > > > link 1 > > > > > Description > > > > > > > > > > > > > > > > link 2 > > > > > Description > > > > > > > > > > > > > > > > link 3 > > > > > Description > > > > > > > > > > > and do: > > > > > > jQuery('.choix').click(function(e) { > > > > > $(this).parent().hide(); > > > > > > }); > > > > > > Then jQuery will iterate through all of the elements on the page with > > > > > a class of 'choix' and attach a click event that hides that links > > > > > parent when clicked on. This keeps your html/javascript much cleaner > > > > > as you do not even need to worry about assigning incrementing id's to > > > > > elements and keeping the numbers matched to another elements id to > > > > > link them. > > > > > > This is not an exact solution for you, but it should point you in the > > > > > right direction and way of thinking about how to use jQuery. > > > > > > Josh > > > > > > On Mar 13, 11:27 pm, macgyver47 wrote: > > > > > > > What it does: > > > > > > jQuery('.choix1').click(function(){ > > > > > > jQuery('#quest1').hide(); > > > > > > When you click on either button related to question 1 it just hides > > > > > > the div id="quest1" > > > > > > What I would like to do is something like: > > > > > > for (i=1; i<=6; i++){ > > > > > > $("choix
[jQuery] Re: jQuery each problem
Unfortunatly it doesn't work if ($(this).val() = 'yes') returns nothing $(this).val() returns "on" no matter if you click on button Yes or button No I have been ckecking jquery doc the best I could and cannot find answer to my question: how to I know if user clicked on button Yes or button No Any other ideas ??? Thanks in advance Jean from France On 14 mar, 17:54, Josh Powell wrote: > $(this).is("eq[0]") > > will not work because, is looks at the list of jquery objects that $ > (this) returns. Which is just one object. > > try giving the input a value of yes or no and doing > > if ($(this).val() === 'yes') > > On Mar 14, 8:51 am, macgyver47 wrote: > > > One more question if this is not abusing your time > > Structure of each question: > > > onclick='q1=1'>Yes > > No > > > > jQuery('.choix').click(function(e) { > > $(this).parent().hide();}); > > > as expected your answer hides the content of the question as expected > > How can I know if first (yes) or second (no) button was clicked > > I tried introducing after $(this).parent().hide(); something like > > if (jQuery(this).is(":eq[0]")) { > > do something > > } > > else > > { > > do something} > > > but it doesn't work ! > > Any ideas ? > > Thanks for help > > Jean from France > > On Mar 14, 9:49 am, macgyver47 wrote: > > > > Thank you very much for a great answer which nearly solved my > > > question in a very elegant way, I have even discovered in studying > > > selectors a little more thouroughly ( jquery doc) that you can use > > > jQuery('.choix').click(function(e) { > > > $(this).parent().parent().hide(); > > > and it will go 2 levels up instead of one as described in you solution > > > Thanks to great people like you Josh I am learning ( slowly) > > > Many thanks > > > Jean from France > > > > On 14 mar, 08:27, Josh Powell wrote: > > > > > Yes, forget about using ID's in this way. That's something you had to > > > > do before using jQuery. Think about how your HTML is structured and > > > > things are named/classed and the order they are in. Take advantage of > > > > how easy it is to traverse the DOM with jQuery. If yo uhave > > > > > > > > > link 1 > > > > Description > > > > > > > > > > > > > link 2 > > > > Description > > > > > > > > > > > > > link 3 > > > > Description > > > > > > > > > and do: > > > > > jQuery('.choix').click(function(e) { > > > > $(this).parent().hide(); > > > > > }); > > > > > Then jQuery will iterate through all of the elements on the page with > > > > a class of 'choix' and attach a click event that hides that links > > > > parent when clicked on. This keeps your html/javascript much cleaner > > > > as you do not even need to worry about assigning incrementing id's to > > > > elements and keeping the numbers matched to another elements id to > > > > link them. > > > > > This is not an exact solution for you, but it should point you in the > > > > right direction and way of thinking about how to use jQuery. > > > > > Josh > > > > > On Mar 13, 11:27 pm, macgyver47 wrote: > > > > > > What it does: > > > > > jQuery('.choix1').click(function(){ > > > > > jQuery('#quest1').hide(); > > > > > When you click on either button related to question 1 it just hides > > > > > the div id="quest1" > > > > > What I would like to do is something like: > > > > > for (i=1; i<=6; i++){ > > > > > $("choix " + i ).click function(){ > > > > > $("#quest"+i).hide(); > > > > > } > > > > > So every time user clicks on any radio button with id="choix1" or > > > > > choix2 or choix3... it will hide the related div with id="quest1" or > > > > > quest 2... > > > > > Any ideas > > > > > Thanks for help > > > > > Jean from France > > > > > > On 14 mar, 00:57, Josh Powell wrote: > > > > > > > What this is doing: > > > > > > > jQuery('.choix1').click(funct
[jQuery] Re: jQuery each problem
One more question if this is not abusing your time Structure of each question: Yes No jQuery('.choix').click(function(e) { $(this).parent().hide(); }); as expected your answer hides the content of the question as expected How can I know if first (yes) or second (no) button was clicked I tried introducing after $(this).parent().hide();something like if (jQuery(this).is(":eq[0]")) { do something } else { do something } but it doesn't work ! Any ideas ? Thanks for help Jean from France On Mar 14, 9:49 am, macgyver47 wrote: > Thank you very much for a great answer which nearly solved my > question in a very elegant way, I have even discovered in studying > selectors a little more thouroughly ( jquery doc) that you can use > jQuery('.choix').click(function(e) { > $(this).parent().parent().hide(); > and it will go 2 levels up instead of one as described in you solution > Thanks to great people like you Josh I am learning ( slowly) > Many thanks > Jean from France > > On 14 mar, 08:27, Josh Powell wrote: > > > Yes, forget about using ID's in this way. That's something you had to > > do before using jQuery. Think about how your HTML is structured and > > things are named/classed and the order they are in. Take advantage of > > how easy it is to traverse the DOM with jQuery. If yo uhave > > > > > link 1 > > Description > > > > > > > link 2 > > Description > > > > > > > link 3 > > Description > > > > > and do: > > > jQuery('.choix').click(function(e) { > > $(this).parent().hide(); > > > }); > > > Then jQuery will iterate through all of the elements on the page with > > a class of 'choix' and attach a click event that hides that links > > parent when clicked on. This keeps your html/javascript much cleaner > > as you do not even need to worry about assigning incrementing id's to > > elements and keeping the numbers matched to another elements id to > > link them. > > > This is not an exact solution for you, but it should point you in the > > right direction and way of thinking about how to use jQuery. > > > Josh > > > On Mar 13, 11:27 pm, macgyver47 wrote: > > > > What it does: > > > jQuery('.choix1').click(function(){ > > > jQuery('#quest1').hide(); > > > When you click on either button related to question 1 it just hides > > > the div id="quest1" > > > What I would like to do is something like: > > > for (i=1; i<=6; i++){ > > > $("choix " + i ).click function(){ > > > $("#quest"+i).hide(); > > > } > > > So every time user clicks on any radio button with id="choix1" or > > > choix2 or choix3... it will hide the related div with id="quest1" or > > > quest 2... > > > Any ideas > > > Thanks for help > > > Jean from France > > > > On 14 mar, 00:57, Josh Powell wrote: > > > > > What this is doing: > > > > > jQuery('.choix1').click(function(){ > > > > jQuery('#quest1').hide(); > > > > > }); > > > > > is looping through every element on the page with a class of 'choix1', > > > > so you could either change all of the elements you want to loop though > > > > classes to choix and then do > > > > > jQuery('.choix').click(function(){ > > > > jQuery(this).parent().hide(); > > > > > }); > > > > > Which will loop through them all and then hide them when either yes or > > > > no is selected or find some other way of identifying every element > > > > that you want to act on. Perhaps use the name field, or if they are > > > > the only radio buttons on the page you can do > > > > > jQuery(':radio') as the selector. > > > > > On Mar 13, 2:45 pm, macgyver47 wrote: > > > > > > Hi > > > > > I am new to jQuery and learning slowly > > > > > Here is the problem > > > > > I have 6 questions each of them has 2 buttons ( yes or no radio > > > > > buttons) > > > > > When user clicks on 1 answer I would like to hide the entire question > > > > > I have achieved to do this for 1 question but no success looping > > > > > through all 6 questions ! > > > > > > > > > onclick='q1=1'>Yes > > > > > No > > > > > > > > > > > > > > onclick='q1=1'>Yes > > > > > No > > > > > > > > > > ... > > > > > jQuery('.choix1').click(function(){ > > > > > jQuery('#quest1').hide(); > > > > > }); > > > > > This works for 1 item but how can I loop through all all of them > > > > > Thanks for help > > > > > Jean from France
[jQuery] Re: jQuery each problem
Thank you very much for a great answer which nearly solved my question in a very elegant way, I have even discovered in studying selectors a little more thouroughly ( jquery doc) that you can use jQuery('.choix').click(function(e) { $(this).parent().parent().hide(); and it will go 2 levels up instead of one as described in you solution Thanks to great people like you Josh I am learning ( slowly) Many thanks Jean from France On 14 mar, 08:27, Josh Powell wrote: > Yes, forget about using ID's in this way. That's something you had to > do before using jQuery. Think about how your HTML is structured and > things are named/classed and the order they are in. Take advantage of > how easy it is to traverse the DOM with jQuery. If yo uhave > > > link 1 > Description > > > > link 2 > Description > > > > link 3 > Description > > > and do: > > jQuery('.choix').click(function(e) { > $(this).parent().hide(); > > }); > > Then jQuery will iterate through all of the elements on the page with > a class of 'choix' and attach a click event that hides that links > parent when clicked on. This keeps your html/javascript much cleaner > as you do not even need to worry about assigning incrementing id's to > elements and keeping the numbers matched to another elements id to > link them. > > This is not an exact solution for you, but it should point you in the > right direction and way of thinking about how to use jQuery. > > Josh > > On Mar 13, 11:27 pm, macgyver47 wrote: > > > What it does: > > jQuery('.choix1').click(function(){ > > jQuery('#quest1').hide(); > > When you click on either button related to question 1 it just hides > > the div id="quest1" > > What I would like to do is something like: > > for (i=1; i<=6; i++){ > > $("choix " + i ).click function(){ > > $("#quest"+i).hide(); > > } > > So every time user clicks on any radio button with id="choix1" or > > choix2 or choix3... it will hide the related div with id="quest1" or > > quest 2... > > Any ideas > > Thanks for help > > Jean from France > > > On 14 mar, 00:57, Josh Powell wrote: > > > > What this is doing: > > > > jQuery('.choix1').click(function(){ > > > jQuery('#quest1').hide(); > > > > }); > > > > is looping through every element on the page with a class of 'choix1', > > > so you could either change all of the elements you want to loop though > > > classes to choix and then do > > > > jQuery('.choix').click(function(){ > > > jQuery(this).parent().hide(); > > > > }); > > > > Which will loop through them all and then hide them when either yes or > > > no is selected or find some other way of identifying every element > > > that you want to act on. Perhaps use the name field, or if they are > > > the only radio buttons on the page you can do > > > > jQuery(':radio') as the selector. > > > > On Mar 13, 2:45 pm, macgyver47 wrote: > > > > > Hi > > > > I am new to jQuery and learning slowly > > > > Here is the problem > > > > I have 6 questions each of them has 2 buttons ( yes or no radio > > > > buttons) > > > > When user clicks on 1 answer I would like to hide the entire question > > > > I have achieved to do this for 1 question but no success looping > > > > through all 6 questions ! > > > > > > > onclick='q1=1'>Yes > > > > No > > > > > > > > > > > onclick='q1=1'>Yes > > > > No > > > > > > > > ... > > > > jQuery('.choix1').click(function(){ > > > > jQuery('#quest1').hide(); > > > > }); > > > > This works for 1 item but how can I loop through all all of them > > > > Thanks for help > > > > Jean from France
[jQuery] Re: jQuery each problem
What it does: jQuery('.choix1').click(function(){ jQuery('#quest1').hide(); When you click on either button related to question 1 it just hides the div id="quest1" What I would like to do is something like: for (i=1; i<=6; i++){ $("choix " + i ).click function(){ $("#quest"+i).hide(); } So every time user clicks on any radio button with id="choix1" or choix2 or choix3... it will hide the related div with id="quest1" or quest 2... Any ideas Thanks for help Jean from France On 14 mar, 00:57, Josh Powell wrote: > What this is doing: > > jQuery('.choix1').click(function(){ > jQuery('#quest1').hide(); > > }); > > is looping through every element on the page with a class of 'choix1', > so you could either change all of the elements you want to loop though > classes to choix and then do > > jQuery('.choix').click(function(){ > jQuery(this).parent().hide(); > > }); > > Which will loop through them all and then hide them when either yes or > no is selected or find some other way of identifying every element > that you want to act on. Perhaps use the name field, or if they are > the only radio buttons on the page you can do > > jQuery(':radio') as the selector. > > On Mar 13, 2:45 pm, macgyver47 wrote: > > > Hi > > I am new to jQuery and learning slowly > > Here is the problem > > I have 6 questions each of them has 2 buttons ( yes or no radio > > buttons) > > When user clicks on 1 answer I would like to hide the entire question > > I have achieved to do this for 1 question but no success looping > > through all 6 questions ! > > > onclick='q1=1'>Yes > > No > > > > > onclick='q1=1'>Yes > > No > > > > ... > > jQuery('.choix1').click(function(){ > > jQuery('#quest1').hide(); > > }); > > This works for 1 item but how can I loop through all all of them > > Thanks for help > > Jean from France
[jQuery] jQuery each problem
Hi I am new to jQuery and learning slowly Here is the problem I have 6 questions each of them has 2 buttons ( yes or no radio buttons) When user clicks on 1 answer I would like to hide the entire question I have achieved to do this for 1 question but no success looping through all 6 questions ! Yes No Yes No ... jQuery('.choix1').click(function(){ jQuery('#quest1').hide(); }); This works for 1 item but how can I loop through all all of them Thanks for help Jean from France