1

Thanks alot to wiz kid & Axel Martinez ! Problem is solved !

works this way:

$(document).ready(function() {
    $("#info").on('click', function() {
        $(".infos").toggleClass("infos_sichtbar");
    });

i am trying to use my button with getElementById, but it won't work :(

The script is for a WebApplikation that is going to be a native App converted by PhoneGap. I want to change the CSS class of an element with the script, so that my div called "infos" is getting visible. It works with this script:

    <script>
    $(document).ready(function() {
        $("button").on('click', function() {
            $(".infos").toggleClass("infos_visible");
        })
    });

    </script>

But the problem is, there are two buttons, one for informations that should get visible with the click and one for legal notices ...

I'm trying to get it work this way:

first attempt:

$(document).ready(function() {
        $.getElementById("info").on('click', function() {
            $(".infos").toggleClass("infos_sichtbar");
        })
    });

second attempt:

 $(document).ready(function() {
        $.getElementById("info").onclick = function() {
            $(".infos").toggleClass("infos_sichtbar");
                    }
                 /* $.getElementById("legalnotice").onclick = function() {
            $(".legalnotice").toggleClass("legalnotice_sichtbar");
        }*/
    });

When im using the script, the click on the button doesn't do anything.

Edit:

HTML Code:

<body>

<div class="infos">Blub blub blub blub blub blub blub blub</div>

<header>
    <h1>App</h1>
</header>
<section>
    <h1>welcome!</h1>
    <p class="einleitung">intro</p>
<aside>
    <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. </p>
</aside><button id="info">Infos</button><button id="impress">Impressum</button>
</section>
<script src="zepto.js"></script>
<script src="app.js"></script>
<script>
window.scrollTo(0,1);
</script>

The script is implemented with the app.js file.

4

2 回答 2

2

尝试使用

$("#info") 

代替

$.getElementById("info")

IE

$(document).ready(function() {
        $("#info").on('click', function() {
            $(".infos").toggleClass("infos_sichtbar");
        });
});
于 2013-03-03T13:45:25.270 回答
1

如果您使用的是 jQuery,为什么不使用选择器,例如

$(document).ready(function() {
    $("#info").click(function() {
        $(".infos").toggleClass("infos_sichtbar");
    });
});
于 2013-03-03T13:49:16.407 回答