0

how I can copy color value from a colorful menu and use it in new page with Jquery?

<a href="page1.php" style="color:#ffcc00">Link1</a>
<a href="page2.php" style="color:#ff0000">Link2</a>
<a href="page3.php" style="color:#00ffff">Link3</a>

page1 > #ffcc00 background
page2 > #ff0000 background
page3 > #00ffff background

2 Answers2

0

This would require more than just jQuery as all variables are reset once the page is relocated. You could use a $.cookie to store the value of the color, or a php GET variable to pass that information to the newly loaded page. You could however use jQuery's .css method to capture the color and then store it in the GET variable or cookie.

$('a').on('click', function(){
    var color = $(this).css('color');
    console.log(color);
});

More info on cookies: How do I set/unset cookie with jQuery?

Hope this helps, and let me know if you have more questions!

Community
  • 1
  • 1
wrxsti
  • 3,434
  • 1
  • 18
  • 30
0

Is it what are you wanting?

With this code you get the color of the link clicked:

    $("a").click(function(){
      console.log($(this).css('color'));
      return false;
    });
brunozrk
  • 773
  • 1
  • 7
  • 14