class name as variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gintare
    New Member
    • Mar 2007
    • 103

    class name as variable

    How to use Jquery variable as css selector?

    For instance,

    Code:
    <script>
    $(document).ready(function(){
      var ind='th78'; //database row index
      var classname='highlight ' + ind;
      spanNode.className = classname; // set css
      $(".highlight.ind").append("text from database with id=ind");
      })
    // this does not work because there should be not word "ind", but value of variable ind. How to select value of variable ind?
    
    //OR
    var spanNode = document.createElement('span');
    var ind='th78'; //database row index
    spanNode.id=ind;
     $("[#id=ind]").append("text from database with id=ind");
    //This also does not work, because instead of ind, i have to compare with variable ind. How to use value of variable ind?
    </script>
    I do not know how to use value of variable as Jquery/css selector.
  • gintare
    New Member
    • Mar 2007
    • 103

    #2
    Working example:
    I'm trying to build a dynamic jquery selector with the following code: var section_id = "{segment_3}"; var num_children = $('#'+ section_id + ' ul').children().size(); where segment_3 is a value I


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

    In my case it would be:
    ind='th78';
    $('span').attr( 'id', ind );
    $("#"+ind).appe nd("text from database with id=ind");

    Comment

    Working...