contents
contents
...">

Assign class through JQuery by selecting random ID

I have a range of divs, each with an incremental ID:
contents
contents
contents
contents
contents
contents
... I'm trying to assign a class through JQuery by selecting by ID: `$('#id').addClass('someClass');` but I want the '#id' to be selected randomly from the range I have there. The range could be sizable, maybe up to 50 ids or more. I'm guessing this will have to read the IDs as number, right? How do I get a random number there? ...Here's the full scheme: setInterval ( "flipit()", 3000 ); function flipit ( ) { $(document).ready(function(){ var elmId = 'nS_' + (Math.floor(Math.random() * 6) + 1); $('#' + elmId).addClass('numSen2'); }); }
contents
contents
contents
contents
contents
contents

Element IDs cannot start with a number.

以上就是Assign class through JQuery by selecting random ID的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏