0

I have a navicon made of css content property.

The code looks like this

#nav:before {
    content: '=';
}
function navigation() {
    $('#navigation').click(function() {
        $('#toggle').slideToggle(600);
        $('#toggle').css({ 
            'content': 'x'
        }); 
    });
}
window.onload = navigation;

<nav id="toggle">
<ul>
<li></li>
</ul>
</nav

This is not working. How can I call default property when the user clicks the x mark?

11
  • i have giver id toggle for nav Commented Nov 21, 2015 at 14:52
  • give style tage for style elements Commented Nov 21, 2015 at 14:55
  • I have not styles yet trying with simple things Commented Nov 21, 2015 at 15:02
  • the main problem in your code is "YOU ARE NOT SUPPOSED TO USE JQUERY IN ONLOAD SECTION" Commented Nov 21, 2015 at 15:04
  • 1
    try on the normay way as $(document).ready(function(){navigation();}); Commented Nov 21, 2015 at 15:08

2 Answers 2

1

You can try something like this https://jsfiddle.net/2Lzo9vfc/149/

HTML

<button>BUTTON</button>
<div class="nav pseudo"></div>

JS

$('button').click(function() {

    $('.nav').slideUp(function() {
        var nav = $(this);
        if(nav.hasClass('pseudo')) {
            nav.removeClass('pseudo');
            nav.addClass('active');
        } else {
            nav.removeClass('active');
            nav.addClass('pseudo');
        }
    }).slideDown();

});

CSS

.nav {
    padding: 5px;
    border: 1px solid black;
    display: inline-block;
}

.active:before {
    content: "x";
}

.pseudo:before {
    content: "=";
}
Sign up to request clarification or add additional context in comments.

Comments

1

maybe this will help you..

function navigation() {
    //$('#toggle').hide();
    $('#click-me').click(function() {
        $('#toggle').slideToggle(600);
        $('#toggle').attr('data-content','pppp');
    });
}
$(document).ready(function(){navigation();});
#toggle:after {
    content: attr(data-content);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="click-me">click me</button>
<nav id="toggle" data-content="xxxeeeee">
</nav>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.