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

class name as variable

100+
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?
  9.  
  10. //OR
  11. var spanNode = document.createElement('span');
  12. var ind='th78'; //database row index
  13. spanNode.id=ind;
  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


100+
P: 103
Working example:
http://stackoverflow.com/questions/4...query-selector

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

In my case it would be:
ind='th78';
$('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.