By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,385 Members | 1,849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,385 IT Pros & Developers. It's quick & easy.

class name as variable

P: 103
How to use Jquery variable as css selector?

For instance,

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. $(document).ready(function(){
  3.   var ind='th78'; //database row index
  4.   var classname='highlight ' + ind;
  5.   spanNode.className = classname; // set css
  6.   $(".highlight.ind").append("text from database with id=ind");
  7.   })
  8. // this does not work because there should be not word "ind", but value of variable ind. How to select value of variable ind?
  10. //OR
  11. var spanNode = document.createElement('span');
  12. var ind='th78'; //database row index
  14.  $("[#id=ind]").append("text from database with id=ind");
  15. //This also does not work, because instead of ind, i have to compare with variable ind. How to use value of variable ind?
  16. </script>
I do not know how to use value of variable as Jquery/css selector.
Jun 21 '15 #1
Share this Question
Share on Google+
1 Reply

P: 103
Working example:

they just add variable:
$('#'+ section_id + ' ul').children().size();

In my case it would be:
$('span').attr('id', ind );
$("#"+ind).append("text from database with id=ind");
Jun 21 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.