$('a.maximize').toggle(
  function () {
    $($(this).attr('href')).animate({
    position: "absolute",
    top: 0,
    left: 0,
    height: '99.5%',
    width: '99.5%',
    opacity: 0.8,
    });
  },
  function () {
    $($(this).attr('href')).animate({
    position: "absolute",
    top: 0,
    left: 0,
    height: '50%',
    width: '50%',
    opacity: 1.0,
    });
);

});

this is a jquery toggle code that i want to resize a href target

erm...can help me to check any wrong with this????

1 answer

Guffa 316
0
points

Remove the trailing commas from after the last item in the animation objects. Use the preventDefault methods to keep the browser from following the href when you click the link. You have an extra ); at the end of the second function, which causes a syntax error.

$('a.maximize').toggle(
  function (e) {
    $($(this).attr('href')).animate({
      position: "absolute",
      top: 0,
      left: 0,
      height: '99.5%',
      width: '99.5%',
      opacity: 0.8
    });
    e.preventDefault();
  },
  function (e) {
    $($(this).attr('href')).animate({
      position: "absolute",
      top: 0,
      left: 0,
      height: '50%',
      width: '50%',
      opacity: 1.0
    });
    e.preventDefault();
  }
);
Answered almost 7 years ago by Guffa
  • need $(document).ready(function() this??? weiloon1234 almost 7 years ago
  • need this ??? $(document).ready(function(){ weiloon1234 almost 7 years ago
  • i have tried your code, is not work ? weiloon1234 almost 7 years ago
  • Yes, you need to run the code in the ready event, so that it runs after the element is created. I have tried the code and it works just fine. Guffa almost 7 years ago