Stuck using onClick app open dialog

Very new to this and stuck with the onClick team, and it puzzled me.

What should happen: The user clicks on the text of the shopping cart (in the div element that was in style) and opens a dialog box containing the contents of the shopping cart.

Here is the code below ...

I think I did a little last week because I probably miss something really easy and just plain stupid.

Any help would be greatly appreciated.

Copy code

<script type="text/javascript">
$(function() {
$( 'div.dialog' ).dialog( {modal:true,autoOpen:false} );
$('CartLink').on( 'click', function() {
    var index = $(this).index() + 1;
    $( '#dialog' +  index ).dialog( 'open' );
});
});
</script>

    <div class="dialog" id="dialog1">Shopping Cart Contents</div>

<div id="CartLink" class="fluid ShoppingCart"><img src="images/Site/Shopping_cart.gif"         
alt="" width="25" height="23"/>Shopping Cart</div>
+3
source share
3 answers

It looks like you are missing #for targeting idhere

$('#CartLink').on( 'click', function() {
//-^ here -----
    var index = $(this).index() + 1;
    $( '#dialog' +  index ).dialog( 'open' );
});

You need to change:

var index = $(this).index() + 1;

at

var index = $(this).index();

index #CartLink 1 not 0 . 1.

+3

# id

$(function() {
    $( 'div.dialog' ).dialog( {modal:true,autoOpen:false} );
    $('#CartLink').on( 'click', function() {
    //.^.....add # here.......
        var index = $(this).index();
        $( '#dialog' +  index ).dialog( 'open' );
    });
});
+4

.index(), . , , , div#CartLink node, html ( div, ..)...) .

- :

<div id="dialog1">...</div>
<div id="CartLink" data-dialog="dialog1" class="...">...</div>


$('#CartLink').on('click', function(){
    var id = $(this).attr('data-dialog');
    $('#'+id).dialog('open');
});
0

All Articles