admin管理员组文章数量:1306037
I want to change HTML dir
attribute once the page loads; how can I do that? Do I need to use the .ready()
function?
Currently it looks like:
jQuery("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");
How can I write it in a script; do i need to write in .ready()
function or .load()
?
<div class="header">
<script src=".js"></script>
<script>
jQuery("html").attr("dir", "rtl")?
</script>
The code appears like this:
This is my CSS
body.right-to-left li {
float:right;
direction: rtl;
}
I want to change HTML dir
attribute once the page loads; how can I do that? Do I need to use the .ready()
function?
Currently it looks like:
jQuery("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");
How can I write it in a script; do i need to write in .ready()
function or .load()
?
<div class="header">
<script src="http://code.jquery./jquery-latest.js"></script>
<script>
jQuery("html").attr("dir", "rtl")?
</script>
The code appears like this:
This is my CSS
body.right-to-left li {
float:right;
direction: rtl;
}
Share
Improve this question
edited Aug 11, 2021 at 7:53
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Dec 25, 2012 at 12:51
user1765876user1765876
7
- 1 use it under $(document).ready – Amyth Commented Dec 25, 2012 at 12:52
- 4 It seems you know the answer. – Ram Commented Dec 25, 2012 at 12:52
-
No, you don't need it. It should work just fine: jsfiddle/Q6c93. Make sure the
html
tag actually has alang=ar
attribute. Of course you'd need.ready
or.load
to attach the class to thebody
. But what exactly is your problem? Is the attribute not changed? Is the class not added? Do you get an error? Where is your code located in the document? The more information you provide, the easier it is for us to help you. – Felix Kling Commented Dec 25, 2012 at 12:55 -
2
every function that is in
$(function () {})
is called after the document has loaded. – AlexandruSerban Commented Dec 25, 2012 at 12:55 - @FelixKling my class doesn't loaded.. I can see my code in view source – user1765876 Commented Dec 25, 2012 at 13:25
1 Answer
Reset to default 6simple as it can be...
put your code inside...document.ready()
<script>
$(document).ready(function(){
$("html[lang=ar]").attr("dir", "rtl")
.find("body").addClass("right-to-left");
});
</script>
and a link that explain about ready()
and load()
function..
http://4loc.wordpress./2009/04/28/documentready-vs-windowload/
本文标签: javascriptChange html dir attribute using jQueryStack Overflow
版权声明:本文标题:javascript - Change html dir attribute using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741814178a2398974.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论