Switch positions of 2 divs with jQuery

I'm wondering if it's posible to switch positions of two divs with jQuery. I have two div like this
STUFF ONE
STUFF TWO
so if `div2` has content (or contains more than just white spaces) it switches the order of `div1` and `div2` so this:
STUFF ONE
STUFF TWO
would become this:
STUFF TWO
STUFF ONE
But if it was this:
STUFF ONE
or this:
STUFF ONE
it wouldn't do anything. Also... if posible, if switched I would like to add a class to `div1`. Any help with this will be very much appreciated. UPDATE: I forgot to add that I have to run this across multipul instanses on the same page. Each instance is formated like this:
STUFF ONE
STUFF TWO
STUFF ONE
STUFF TWO

以上就是Switch positions of 2 divs with jQuery的详细内容,更多请关注web前端其它相关文章!

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

评论 抢沙发

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

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

联系我们

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

支付宝扫一扫打赏

微信扫一扫打赏