admin管理员组

文章数量:1332388

I have four buttons on the page, when I click on one of them i want it to be highlighted.

The buttons are used to pass data to a controller. They are like this:

<button name="region" id="region" type="button"  onclick="window.location='/project/Viewdata/index/region/1'" class="current">ALL</button>
<button name="region" id="region2" type="button"  onclick="window.location='/project/Viewdata/index/region/2'" class="current">1st</button>

I have four buttons on the page, when I click on one of them i want it to be highlighted.

The buttons are used to pass data to a controller. They are like this:

<button name="region" id="region" type="button"  onclick="window.location='/project/Viewdata/index/region/1'" class="current">ALL</button>
<button name="region" id="region2" type="button"  onclick="window.location='/project/Viewdata/index/region/2'" class="current">1st</button>
Share edited Jul 11, 2017 at 22:15 J. Lavoie 3343 gold badges5 silver badges24 bronze badges asked Jul 19, 2013 at 13:17 user2595861user2595861 831 gold badge2 silver badges9 bronze badges 8
  • 4 You can't have two elements with the same id! – bfavaretto Commented Jul 19, 2013 at 13:18
  • 2 buttons have redirect code. wouldn't they redirect after click? – user1 Commented Jul 19, 2013 at 13:19
  • yes that is a problem i am facing, because of redirect option its loading the basic settings – user2595861 Commented Jul 19, 2013 at 13:21
  • is there any reason not to use normal links? – bitWorking Commented Jul 19, 2013 at 13:21
  • and i changed the id's :) – user2595861 Commented Jul 19, 2013 at 13:21
 |  Show 3 more ments

1 Answer 1

Reset to default 4

check this JSFiddle

basically, you bind a highligt effect to the button with jQuery, when clicking it like this

$('button').click(function() {
    $(this).effect( "highlight", {color: 'red'}, 3000 );
});

NOTE: As said in the ments, you should never have 2 elements with the same id on one page. If you want to use the same descriptor, use class instead of id

本文标签: javascriptHow to highlight a button in html page when i click on itStack Overflow