-1

I try to have access to the row i clicked to add or remove a class, but it seems like i misinterpreted the value of this. Isn't it supose to be the DOM where the event go called (in this case, the <li>)? Here is my code:

JAVASCRIPT

$(document).on('click', '.ToDownload', function() 
        {
            if($(this).className.lastIndexOf("isSelected") != -1)
            {
                $(this).addClass("isSelected");
                $(this).css('border', '2px solid #000099')
            }
            else
            {
                $(this).removeClass("isSelected");
                $(this).css('border', 'none')
            }
        });

HTML

<li id="addedDownloadFileRow" class="fitting ToDownload">
    <a href="#">
        <div class="ui-grid-a">
            <div class="ui-block-a">test1</div>
            <div class="ui-block-b">test2</div>
        </div>
    </a>
</li>

In fact, i thought i could use the property className to find if my row is already selected, but it seems like this isnt the DOM of the <li> tag. Any information or a way to see what this really is would be appreciated.

P.S. The class "fitting" is only used for some css purpose.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
MacGruber
  • 162
  • 2
  • 13
  • 3
    @azium presumably because of the `'.ToDownload'` in the call to `on()` – CupawnTae Oct 29 '15 at 19:57
  • And `console.log(this)` or `console.dir(this)` will pretty much tell you what you want. – azium Oct 29 '15 at 19:57
  • I would use `if($(this).is(".isSelected"))` to check if the element is selected instead – Musa Oct 29 '15 at 19:57
  • "this" is referring to the current element and the basic syntax is: `$(selector).action()` – Adam Buchanan Smith Oct 29 '15 at 19:58
  • @CupawnTae oh gosh, thanks I skimmed over that somehow. – azium Oct 29 '15 at 19:58