jquerytemplatesmeteordom-eventsmeteor-helper

How can fetch the text from html tag in meteor template event?


How can I get "option 1" from below code:

<template name="MyTemplate">
   <div class="dropdown">
      <a class="dropdown-toggle count-info" data-toggle="dropdown" href="#" aria-expanded="false">
         <button type="button" class="btn btn-sm btn-primary">Add</button>
      </a>
      <div class="dropdown-menu dropdown-alerts">
         <form method="post" id="some-form" data-remote="true" accept-charset="UTF-8">
            <div class="form-group">
               <label>Select Option</label>
               <div class="input-group">
                  <select class="chosen-select" tabindex="2">
                     <option value="op1">Option 1</option>
                     <option value="op2">Option 2</option>
                     <option value="op3">Option 3</option>
                  </select>
               </div>
            </div>
            <input type="submit" value="Add" data-disable-with="Saving..." class="btn btn-sm btn-success">
         </form>
      </div>
   </div>
</template>

I am using chosen plugin (http://harvesthq.github.io/chosen/) for style. So, dropdown node converts differently and there one node is like:

<a class="chosen-single" tabindex="-1">
    <span>Option 1</span>
</a>

Which holds the selected value from the dropdown.

Inside template event my code is:

template.find("#some-form .chosen-single span");

It is giving me:

<span>Option 1</span>

I want "Option 1" from it. if I write like this:

// giving "undefined"
template.find("#some-form .chosen-single span").html; 
or
// giving error :: Uncaught TypeError: undefined is not a function
template.find("#some-form .chosen-single span").html();

Solution

  • template.find("#some-form .chosen-single span").text();