1

How does one get a nested form id while using jquery?

lets say the form is

<form id="search-theme-form">
<div id = "search">
   <div id="edit-search-theme-form-1-wrapper" class="form-item">
   </div>
   <input id="edit-submit" class="form-submit btn">
</div>
</form>

will it be

$('#search-theme-form').submit(function () {
    $('#search #edit-submit').click(function () {
        if ($("#search input:text").val() == "Search this community..." || $("#search input:text").val() == "") {
            alert("Please enter a search term");
            return false;
        }
    });
});
6
  • 2
    I don't understand what you mean. Commented Jan 11, 2011 at 21:03
  • 1
    1 mistake in your code $("$edit-submit").click() should be $("#edit-submit").click() Commented Jan 11, 2011 at 21:07
  • 2
    Can you clarify your question, it doesn't make much sense. Thanks! Commented Jan 11, 2011 at 21:08
  • For #search input:text to work you’ll have to specify type="text" on your <input>. Commented Jan 11, 2011 at 21:29
  • I still don’t get your question. What does your jQuery code have to do with nested IDs? What’s your problem with the code you provided? Commented Jan 11, 2011 at 21:30

2 Answers 2

6

jQuery uses CSS-type selectors. To get a sub-id select like

jQuery('#search #edit-submit');
Sign up to request clarification or add additional context in comments.

Comments

2

I think you're missing a form tag. :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.