Welcome Guest, Not a member yet? Register   Sign In
Cannot Toggle Arrows in a Table - Jquery
#1

[eluser]Shiju S S[/eluser]
I have the script to toggle down and up arrows in a table
Code:
<$cript type="text/javascript">
$('th').click(function() {
var th_index = $(this).index();
$("th:not(':eq(th_index)')").children('i').attr( 'class', 'pull-right icon-chevron-down' );
$('th').eq(th_index).children('i').toggleClass("icon-chevron-up icon-chevron-down");
});
</$cript>

$("th:not(':eq(th_index)')")
Cannot eliminate the selected column to down arrow.

Table Structure
Code:
<table class="table table-striped table-bordered bootstrap-datatable datatable">
<thead>
<tr>
<th width="8%">Slno<i class="pull-right icon-chevron-down"></i></th>
<th width="10%">Track ID<i class="pull-right icon-chevron-down"></i></th>
<th width="25%">Name<i class="pull-right icon-chevron-down"></i></th>
<th width="10%">Mobile<i class="pull-right icon-chevron-down"></i></th>
<th width="10%">Joined On<i class="pull-right icon-chevron-down"></i></th>
<th width="10%">Activated<i class="pull-right icon-chevron-down"></i></th>
<th>Actions</th>
</tr>
</thead>  
<tbody>
#2

[eluser]Unknown[/eluser]
Well, I think so, this isn't supposed to be in a codeigniter forum, as it appears to be a jquery problem.
Don't use attr to set a class; use addClass/removeClass,toggleClass.
Also, you are supplying 2 classes in the toggleClass method, I am not sure you can do that.
And I think so, you need to supply a valid selector inside not(), whereas :eq() is not a complete css selector, its kind of a helper.
If after this it still doesn't work, try using .eq() instead of (":eq()") as the jquery selector.
#3

[eluser]Shiju S S[/eluser]
Changing
Code:
$(“th:not(’:eq(th_index)’)”)
to
Code:
$(“th:not(’.eq(th_index)’)”)

Solved the problem.

Quote:I am posting it here due to two reasons:
1. I do not know the correct place to post request for jquery.
2. Codeigniter forum usually helps me solve most of my problems, that too quickly. As you did now





Theme © iAndrew 2016 - Forum software by © MyBB