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 a lang=ar attribute. Of course you'd need .ready or .load to attach the class to the body. 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
 |  Show 2 more ments

1 Answer 1

Reset to default 6

simple 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