Friday 15 March 2013

html - offset().top is null or not an object error in JQuery -


I have a live live demo here:

What am I going to do when 1 box should be clicked, the first section should scroll, when the 2 box is clicked, it should scroll in the second section and even further. But when I click on the numbers, I get the following error:

Offset (). Whether the top item is zero or not

My JQuery looks like:

  $ (function () {$ (". Pointto"). Mouseover (function $ ("$"); $ (This) .addClass ("hover"); $; ($ ("(". "), $ (" Pointto "). MouseDown (function () {$ (this) $ (". ") ; $ ("Point"). Mouse (function () {$ (this) .removeClass ("pressed");}); $ (document) .on ('click', '. (', ''); By clicking on '1' [name = "'",' A '+ Nn +' ']]; // 1, I would like to add a name to  t = $ (' a [ Name = '' + nn + '"]' '). Offset (). Top; // t = $ (' a [name = '' + nn + ''] '). Offset (). Top; $ ( 'Body, html'). Chetan ({scrollTop: t}, 800);});});   

HTML Sample:

  & lt; an id = "s01" square = "dot" and gt; 1 & lt; / a & gt; // clickable link ... .. ... ... about a name = "01" & gt; 1 & lt; / a & gt; // target   

to resolve the error Also consider?

Update: [Solution]

  $ (document) .on (pressed 'click', 'again. Gone, .pointto ', function () {var nn = $ (this) .attr (' id '). ('S', ';); Warning ('a [name =' + + nn + ']'); T = $ ('a [name =' '+ nn +' ']'). Offset (). Top; // t = $ ('A [name = "' + nn + '"]'). Offset (). Top; $ ('Body, html') Chetan ({scrollTop: t}, 800);}); Depending on your post HTML, you have it:    

< Code> var nn = $ (this) .attr ('id'). Replace ('a', ''); id is s01 , nn is now set to s01

>, Because there is no "A" in the id, nothing changes

  t = $ ('a [name =' '+ nn +' ']'). Offset () top;   

Then you search for a with the name for s01 . Your anchor does not have this name, your anchor name is 1 anything is offset tap, so you try to get the property of zero top .

No comments:

Post a Comment