最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery - "highlight" effect help - Stack Overflow

programmeradmin2浏览0评论

Looking at the "highlight" JQuery effect:

You can change the background color of any DIV to fade in/out

However, the example is to "highlight" on a "click" event

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});

How can I programatically call the highlight method as though it was a function within my code (instead of activate on a 'click' event)?

Looking at the "highlight" JQuery effect:

http://docs.jquery.com/UI/Effects/Highlight

You can change the background color of any DIV to fade in/out

However, the example is to "highlight" on a "click" event

$("div").click(function () {
      $(this).effect("highlight", {}, 3000);
});

How can I programatically call the highlight method as though it was a function within my code (instead of activate on a 'click' event)?

Share Improve this question asked Aug 17, 2009 at 12:54 TimJKTimJK 4752 gold badges8 silver badges13 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 13
$("div").effect("highlight", {}, 3000);

As pointed by JorenB this will highlight all the div's in your page.

If you only want to highlight one div like:

<div id="myDiv"></div>

You should do:

$("div#myDiv").effect("highlight", {}, 3000);

If you want to highlight all div's with a specific classe you cand do:

<div id="myDiv1" class="myClass"></div>
<div id="myDiv2" class="myClass"></div>

$("div.myClass").effect("highlight", {}, 3000);

For more information on selectors see JQuery Selectors.

it would simply be

$([your selector]).effect("highlight", {}, 3000);

You can also achieve that by triggering the click event, if you have that in your click handler anyway:

$('div').click();

or:

$('div').trigger('click');
发布评论

评论列表(0)

  1. 暂无评论