Leo Jiang
Leo Jiang

Reputation: 26145

Selecting multiple children with same parent in CSS

I'm using PHPQuery, which is a PHP port of jQuery, so it also uses CSS selectors. However, one difference is that PHPQuery does not return matched elements in the document order when there are multiple selectors.

Is it possible to combine this into one selector?

#article>p,#article>blockquote

The only other solution I can think of is:

#article>*:not(div):not(table):not(ul):not(...

Upvotes: 4

Views: 169

Answers (2)

Ram
Ram

Reputation: 144699

I haven't used phpQuery(till 5 minutes ago) but as it works like jQuery, using it's .filter() method should do the trick, the idea is selecting all the children and then filtering the elements that match the criteria.

$doc['#article']->children()->filter(function($i, $element) {
    return in_array($element->tagName, array('blockquote', 'p'));
})->foo();

Upvotes: 1

Adil
Adil

Reputation: 148150

You can combine the selector use add()

$('#article>p').add('#article>blockquote')

Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to .add() can be pretty much anything that $() accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet, jQuery api.

Upvotes: 0

Related Questions