tags:

views:

21

answers:

1

I have two elements on a page.

<div id="a">content</div>
<div id="b" style="display:none">different content</div>

When I click the currently displayed div, I want to hide it and show the other one. This is easy to do:

$('#a').hide();
$('#b').show();

But now I want to take it a step further and highlight the element as it is being displayed. I think that it will involve effect("highlight"), but I can't get it to work. How do I achieve this?

+1  A: 

First thing is to correct your ID attributes. They are not allowed to start with a number.

Given that, you probably just need to load jQueryUI. It is required for that effect to work.

http://jqueryui.com/demos/effect/

Here's an example: http://jsfiddle.net/r6pKn/

HTML

<div id="div1">content</div>
<div id="div2" style="display:none">different content</div>​

jQuery

$('#div1').click(function() {
   $(this).hide();
   $('#div2').show().effect('highlight');
});​
patrick dw
sorry, i just used 1 and 2 for example purposes, but you are right, you can't have ids that start with a number
Andrew
@Andrew - Not a problem. Did you get it working?
patrick dw
no, not yet. can't get it to work. I just added jquery-ui-1.7.3
Andrew
@Andrew - What version of jQuery are you using? And what does your actual code look like? You can edit your question if needed.
patrick dw
jQuery 1.3.2. That's why I chose jQuery UI 1.7.3. My code looks exactly the same. Your jsfiddle example is working, so it must be right. I've decided to move on since I can't figure out how what's wrong in my environment.
Andrew
@Andrew - Alright. Only other thing I'd suggest is to make sure you have the javascript loaded in the proper order. jQuery, then jQueryUI, then your javascript. Best of luck. :o)
patrick dw