1

The following code does not work in Firefox

var selectedCategories = $("#category_filter .checkbox-input-group .checked").find("span");
for (var i = 0; i < selectedCategories.length; i++) {
    categories.push(selectedCategories[i].innerText);
} 

Please tell me how I can get a similar result

Ram
  • 143,282
  • 16
  • 168
  • 197
Pavel
  • 1,015
  • 3
  • 13
  • 27

2 Answers2

1

innerText is a non-standard property and Firefox doesn't support it, you should use textContent instead. However, it should be noted that IE8 and below do not support the textContent property.

I would suggest using jQuery .eq() and .text() methods:

categories.push(selectedCategories.eq(i).text());

Also note that for creating arrays you can also use the jQuery .map() method:

var arr = selectedCategories.map(function() {
     return $(this).text();
     // Alternatively:
     // return (this.innerText || this.textContent);
}).get();
Ram
  • 143,282
  • 16
  • 168
  • 197
0
 var selectedCategories = $("#category_filter .checkbox-input-group .checked").find("span").length;
 var categories = [];

    for (var i = 0; i < selectedCategories; i++) {
        categories.push(selectedCategories[i].innerText);
} 
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49