Question

I am trying to use jquery in my joomla article.

what i am trying to do it this-http://jsfiddle.net/bhaveshj21/BYgaq/

<script>
$("#myul > li").click(function(){
    $('li').each(function(){
        var data = $(this).find('a').attr('href');
        $(data).css({'display' : 'none'});
    });
    var curr = $(this).find('a').attr('href');
    $(curr).css({'display' : 'block'}).find('img').animate(
        {
            'width' : '100%',
            'height' : 'auto'
        },
        1000
    );
});</script>

html code is

<div class="menu">
<ul id = "myul">
    <li><a href="#1" id="all">all</a></li>
    <li><a href="#2" id="joomla">joomla</a></li>
    </ul>
</div>
<div class="image" id='1'>
    <img src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRgMHchGIXBuBlMQHUfdTvzpuAaC43tSq3SYgHAsbXNr2TUQwhLYRu8yuSf"/>
    <img src="http://t1.gstatic.com/images?q=tbn:ANd9GcTHHRfptpToJ6GqtsSatdZ-vh36VrIXWokRdYSnc4FEkHncQHLHpw" />

</div>
<div class="images" id='2'>
    <img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSLyEyENGyUVfnLMOPFVAT5gRQw8Mc_koSZWMfrdQLohY8cL1RDGeXKjnRO" />
    </div>

//css

.menu
{
    width:100%
        float:left;
}
.menu a{
    background-color:lightblue;
    border-radius:8px 8px 8px 8px;
    margin-right:10px;
    padding-top:10px;
    padding-left:10px;
    padding-bottom:5px;
    color:black;
    padding-right:30px;
}
.menu li
{
    display:inline;
}
.menu a:hover
{
    background-color:white;
}
.image
{
    display:none;

}
.images
{
    display:none;
}

It is working fine in jsfiddle but not in my joomla temolate.

what I have done is that I have added yhe script file in index.php and my html code in article. the css is working fine not js.

stuck for a while any help will be grate?

Was it helpful?

Solution

Try

<head>
<!--- the head elements -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>    
</head>
<script type="text/javascript>
    (function($){
        $(document).ready(function(){
            $("#myul > li").on("click", function(){
                $('li').each(function(){
                    var data = $(this).find('a').attr('href');
                    $(data).css({'display' : 'none'});
                });
                var curr = $(this).find('a').attr('href');
                $(curr).css({'display' : 'block'}).find('img').animate(
                    {
                        'width' : '100%',
                        'height' : 'auto'
                    },
                    1000
                );
            })
        });
    })(jQuery);
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top