Yar
Yar

Reputation: 7476

Select inner element with no id by JQuery

Say I have this div block:

<div id="some_id" style="display: none;">
    <form action="someAction" method="post">
        <input type="hidden" name="some-name" value="some-value">
    </form>
</div>

I need to the select the form inside this div. I am able to select the div by $('#some_id') but when I try to select the form by $('#some_id').find('form') (or get or $('#some_id:form')) I get this error:

Uncaught TypeError: $(...).find is not a function

Any possible solution?

Upvotes: 1

Views: 441

Answers (2)

Taplar
Taplar

Reputation: 24965

There is nothing wrong with what you attempted, provided that jQuery is properly included in your page and you are properly referencing it with $ or jQuery if it is in noConflict mode.

console.log(
  $('#some_id').find('form').get()
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="some_id" style="display: none;">
    <form action="someAction" method="post">
        <input type="hidden" name="some-name" value="some-value">
    </form>
</div>

Upvotes: 1

Get Off My Lawn
Get Off My Lawn

Reputation: 36351

You don't want a : to select the child you want >

Your selector should look like this:

$('#some_id > form')

Also make sure you are including jQuery, it looks like your code cannot find it.

Upvotes: 0

Related Questions