开发者

How do I call the same function with different div IDs?

I have two divs with different ids (#washing, #bleaching). How can I use a function for different IDs. I have tried adding both the IDs together $("#washing, #bleaching"), but the function is not working correctly on the divs.

Here is the code:

$(function() {
    $("#washing").paginate({
        count: 开发者_JAVA技巧10,
        start: 1,
        display: 7,
        border: true,
        border_color: '#fff',
        onChange: function(page) {
            $('._current', '#paginationdemo').removeClass('_current').hide();
            $('#p' + page).addClass('_current').show();
        }
    });
});


$("#washing, #bleaching") seems right.

  • Check if there was any errors thrown. This code block may have been skipped due to this.
  • Assuming there was no error. Could you just try this:

    $(function() { $("#washing, #bleaching").addClass('testclass').paginate({ //same as given by you }); });

The code is almost same as you have written but I have added the addClass call before paginate call. check if the class names are getting added. if yes, then the problem is not in $ method but must be something to do with the paginate method.


Provide a same class name for two div and use as

 $(function() {
    $("div.class_name").paginate({
        count: 10,
        start: 1,
        display: 7,
        border: true,
        border_color: '#fff',
        onChange: function(page) {
            $('._current', '#paginationdemo').removeClass('_current').hide();
            $('#p' + page).addClass('_current').show();
        }
    });
});


Your multiple selector syntax is correct. But the problem is that #paginationdemo is a single element. How can you paginate two divs with a single pager. Make paginationdemo a CSSClass selector and append it to the parentdiv

Multiple Selectors in jQuery


$('#washing,#bleaching,#div3').hide();

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQUERY: Same function for multiple elements</title>
<?php
# jquery
include_once("latest_jquery.php");
?>
<!-- Page Script -->
<script type="text/javascript">
$(function(){
    $('#washing,#bleaching,#div3').hide();
});
</script>
</head>
<body>
<h2>jQuery: Using the same function for different elements</h2>
<h4>Test: hide these divs</h4>
div 1:
<div id="washing" style="border:solid 1px; height:20px;"></div>
div 2:
<div id="bleaching" style="border:solid 1px; height:20px;"></div>
div 3:
<div id="div3" style="border:solid 1px; height:20px;"></div>
</body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜