Saturday, 15 June 2013

javascript - using tr:nth-child(n) selector in a jQuery function -



javascript - using tr:nth-child(n) selector in a jQuery function -

i know little jquery, i'm not @ 'real' javascript. create next lines lot simpler:

$('.product tr:nth-child(2) .knop',window.parent.document).bind("click", function(){ $('#edit-submitted-data-cursus').val($('.product tr:nth-child(2) .cursus a',window.parent.document).html()) $('#edit-submitted-data-cursusdatum').val($('.product tr:nth-child(2) .datum',window.parent.document).html()) $('#edit-submitted-data-opleidingscode').val($('.product tr:nth-child(2) .code',window.parent.document).html()) $('#edit-submitted-data-cursuslocatie').val($('.product tr:nth-child(2) .loc',window.parent.document).html()) $('#edit-submitted-data-cursustarief').val($('.product tr:nth-child(2) .tarief',window.parent.document).html()) }); $('.product tr:nth-child(3) .knop',window.parent.document).bind("click", function(){ $('#edit-submitted-data-cursus').val($('.product tr:nth-child(3) .cursus a',window.parent.document).html()) $('#edit-submitted-data-cursusdatum').val($('.product tr:nth-child(3) .datum',window.parent.document).html()) $('#edit-submitted-data-opleidingscode').val($('.product tr:nth-child(3) .code',window.parent.document).html()) $('#edit-submitted-data-cursuslocatie').val($('.product tr:nth-child(3) .loc',window.parent.document).html()) $('#edit-submitted-data-cursustarief').val($('.product tr:nth-child(3) .tarief',window.parent.document).html()) }); $('.product tr:nth-child(4) .knop',window.parent.document).bind("click", function(){ $('#edit-submitted-data-cursus').val($('.product tr:nth-child(4) .cursus a',window.parent.document).html()) $('#edit-submitted-data-cursusdatum').val($('.product tr:nth-child(4) .datum',window.parent.document).html()) $('#edit-submitted-data-opleidingscode').val($('.product tr:nth-child(4) .code',window.parent.document).html()) $('#edit-submitted-data-cursuslocatie').val($('.product tr:nth-child(4) .loc',window.parent.document).html()) $('#edit-submitted-data-cursustarief').val($('.product tr:nth-child(4) .tarief',window.parent.document).html()) });

,etc,etc (i have 30 of these blocks of code. sure there way rid of redundant code, did not succeed yet. using code populate fields in form. help much appreciated!

you can utilize loop.

var i; (i = 1; < 41; i++) { $('.product tr:nth-child(" + + ") .knop', window.parent.document).bind("click", function () { $('#edit-submitted-data-cursus').val($('.product tr:nth-child(" + + ") .cursus a', window.parent.document).html()) $('#edit-submitted-data-cursusdatum').val($('.product tr:nth-child(" + + ") .datum', window.parent.document).html()) $('#edit-submitted-data-opleidingscode').val($('.product tr:nth-child(" + + ") .code', window.parent.document).html()) $('#edit-submitted-data-cursuslocatie').val($('.product tr:nth-child(" + + ") .loc', window.parent.document).html()) $('#edit-submitted-data-cursustarief').val($('.product tr:nth-child(" + + ") .tarief', window.parent.document).html()) }); }

javascript jquery css

No comments:

Post a Comment