jQuery Set Select Index

I have an select box: <select id=”selectBox”> <option value=”0″>Number 0</option> <option value=”1″>Number 1</option> <option value=”2″>Number 2</option> <option value=”3″>Number 3</option> <option value=”4″>Number 4</option> <option value=”5″>Number 5</option> <option value=”6″>Number 6</option> <option value=”7″>Number 7</option> </select> I’d like to set one of the options as “selected” based on it’s selected index. For example, if I am trying to set … Read more

jQuery: Check if div with certain class name exists

Using jQuery I’m programmatically generating a bunch of div‘s like this: <div class=”mydivclass” id=”myid1″>Some Text1</div> <div class=”mydivclass” id=”myid2″>Some Text2</div> Somewhere else in my code I need to detect if these DIVs exist. The class name for the divs is the same but the ID changes for each div. Any idea how to detect them using … Read more

Get a list of checked checkboxes in a div using jQuery

I want to get a list of names of checkboxes that are selected in a div with certain id. How would I do that using jQuery? E.g., for this div I want to get array [“c_n_0”; “c_n_3”] or a string “c_n_0;c_n_3” <div id=”checkboxes”> <input id=”chkbx_0″ type=”checkbox” name=”c_n_0″ checked=”checked” />Option 1 <input id=”chkbx_1″ type=”checkbox” name=”c_n_1″ />Option … Read more

jQuery delete all table rows except first

Using jQuery, how do I delete all rows in a table except the first? This is my first attempt at using index selectors. If I understand the examples correctly, the following should work: $(some table selector).remove(“tr:gt(0)”); which I would read as “Wrap some table in a jQuery object, then remove all ‘tr’ elements (rows) where … Read more

Not class selector in jQuery

Is there a simple selector expression to not select elements with a specific class? <div class=”first-foo” /> <div class=”first-moo” /> <div class=”first-koo” /> <div class=”first-bar second-foo” /> I just want to get the first three divs and tried $(div[class^=”first-“][class!=”first-bar”]) But this receives all as the last div contains more than first-bar. Is there a way … Read more

jQuery first child of “this”

I’m trying to pass “this” from a clicked span to a jQuery function that can then execute jQuery on that clicked element’s first child. Can’t seem to get it right… <p onclick=”toggleSection($(this));”><span class=”redClass”></span></p> Javascript: function toggleSection(element) { element.toggleClass(“redClass”); } How do I reference the :first-child of element? 11 Answers 11