简体   繁体   中英

Change property on jQuery element

I'm not a very skilled javascript programmer, so i don't know how to do this the correct way.

I have this script

<script type="text/javascript">
    jQuery(function() {  
            jQuery("#brand-select").jMyCarousel({  
                    visible: '100%' ,
            auto: true,
            speed: 1000,
            });
    });

</script>

Which i working properly, but i want to change the property 'auto: true' to 'auto: false' when the mouse is over the ul element 'brand-select'

I want to do something like this (pseudo-code)

jQuery('#brand-select').mouseover(function() {
  brand-select-carousel.auto = false;
});

Does anybody know how to do this?

I have checked your plugin, as the 'auto' property is not exposed to public, so if you want to change this value, you need to modify this plugin.

Add the a public method before 'return this.each(...)' in flie jMyCarousel.js

this.setAuto = function(value){
    if(typeof value != 'boolean' || value == null){
        return;
    o.auto = value;
};

Then you could get instance of jMyCarousel in the constructor and then use it's public method:

var jMyCarouselInstance;
jQuery(function() {  
        jMyCarouselInstance = jQuery("#brand-select").jMyCarousel({  
            visible: '100%' ,
            auto: true,
            speed: 1000,
        });
});
...
jMyCarouselInstance.setAuto(false);

If you want to get or set the property of an element, use the 'attr' api of jquery: http://api.jquery.com/attr/

jQuery('#brand-select').mouseover(function() {
    jQuery(yourSelector).attr('auto', false);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM