I am trying to select :nth-child
using jquery, but it show syntax error.
Error: Syntax error, unrecognized expression: :nth-child
Here is my code
var i;
jQuery('#' + id + ' .tab-pane').each(function (id, t) {
var n = jQuery(this).attr('id', 'pane-' + t);
var p_id = n.attr('id');
jQuery('#' + id + ' .nav-tabs li:nth-child(' + i + ') a').attr('href', p_id);
i++;
});
please check my code what is missing here
On the first iteration, there is no value for i
. So the query looks like this:
jQuery('#' + id + ' .nav-tabs li:nth-child(undefined) a').attr('href', p_id);
On following iterations, it will be undefined++
, which is NaN
, which still won't work.
This obviously won't work. The solution is to set i
to 1
(or to whatever value is necesary) on the first loop:
var i = 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With