jquery - further querying "this" - jquery-selectors

i want to further use css selectors on "this" how can i do it? specifically i am trying to select this's sibiling ul > li > a's
how can i do it?
this + ul > li > a
i find that using sibling i cannot do .sibling("ul > li > a"), but i can use 3 .siblings() to do it? maybe i am using the wrong function? maybe i shld use find()? but the 1st "operator" i want is to get the sibling ul (i think i can also use next("ul")?)

$('ul>li>a', this) if I understood correctly.
Or
$(this).siblings('ul').find('>li>a')

Related

Parse and rewrite CSS with Electron and ReactJS

I'm writing a desktop application with Electron and ReactJS that edits CSS files. I need to scan the CSS looking for a class selector, and then clear the following declaration block and add some new properties.
The tricky part is matching the class in the selector. I need the class to be the actual target (not a parent), but there might be multiple comma-separated selectors, and so I need to check all of them. For example, in this file I'm searching for the containerApp class:
.section-main .section-right , .menu .container-manu , .containerApp .container-nav {
background: black;
}
.section-main2 .section-left , .menu .container-manu , .section-group-d .containerApp {
background: red;
}
The first block doesn't match because .containerApp is only mentioned as the parent of the real target, .container-nav. The second block does match, and I would want to remove the background: red; and replace it with something else.
What's the best way to go about doing this CSS matching and rewriting?

Nested blockquotes in Draft JS

I'm curious if it's possible to nest blockquote in draft js? At the moment I'm using convertFromHTML to convert a series of nested blockquote tags into ContentState but it seems only the first blockquote is being counted.
Thanks!
You can nest inline styles but you might have to provide your own blockRenderMap to do so. Check out the LaTex example, and draft-js-plugins
In draft js the blockquote is a BlockType and block cannot nest block so you cannot approach it.
But you can use custom inline-style or custom block to simulate it. Inline style can nest and you can make some text display: 'block'; borderLeft: 2px solid #ccc; through draft js decorator. And you can create a react component that can receive a tree like data and render as a nested blockquote, use it as a custom block will also approach your goal.
Blockquote is block type element in HTML, generally block don't nest block element so I wonder what content need nest blockquote?

How to traverse DOM in ExtJS using CSS3/XPath?

Here's my sample HTML:
I would like to modify the content of the highlighted div to "New Title".
Here's my current code:
var divTitle = Ext.select('div[id="main_form"]/table/tbody/tr[1]/td/table/tbody/tr[1]/td/div/div[2]/div');
It seems that it is not working. I got that from using Chrome browser and copying the XPath. Can someone help or guide me here?
Also, I believe you can also simplify the query using the CSS select (in my case 'pt_title') so please mention how that can be coded too.
Thanks in advance.
Found one solution (using CSS selector):
var divTitle = Ext.select('#main_form div.pt_title');
I'm still interested on the other solution wherein you really have to go down each element. I believe this is the equivalent in jQuery:
var divTitle = $('#main_form > table > tbody > tr:nth-child(1) > td > table > tbody > tr:nth-child(1) > td > div > div:nth-child(2) > div');
divTitle.update('New Title');

Zend_Navigation: How to add numberings in the menu items?

I am generating XML from database records, then feeding it to Zend_Navigation to render it as treeview and before rendering I would like to add the level numbers, like a TOC numberings:
I have:
$partial = array('partials/menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);
echo $this->navigation()->menu()->setUlClass('treeview')->render();
The output is dressed with ul/li(I need ul for treeview):
My First Web Page
Nice Page
Main Help
Works
But I Need:
1.My First Web Page
1.1 Nice Page
1.1.1 Main Help
1.2 Works
How can I dress each level with a number?
$navarray=$this->navigation()->menu()->toArray();
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($navarray[0]), RecursiveIteratorIterator::SELF_FIRST);
foreach ($it as $row) {
/// ????
}
Thanks Arman.
Maybe you could modify the partial to render an ol instead of ul, and then use some CSS magic to render the numbering properly.
You can see the example #48 in the Menu Helper documentation to get some inspiration.
EDIT:
If you need to use the ul tag, then probably you'll need to add the "current depth" of the menu items by hand. There is a very similar question answered here: PHP RecursiveIteratorIterator: Determining first and last item at each branch level.
Hope that helps,

I'm trying to select the adjacent sibling of "this" in jquery

$(this+"p").slideDown("slow");
$(this)+$("p").slideDown("slow");
$("this+p").slideDown("slow");
does not work.
Yeah, your syntax is bad. You should use the jQuery Sibling function:
$(this).siblings().find("p").slideDown("slow");
The jQuery API site is awesome for looking stuff like this up, I rely on it nearly daily. I'd keep an eye on it.
Next.
$(this).next("p").slideDown("slow")
Make sure that the "p" element is directly adjacent, though. Otherwise you'll want to use nextAll.
jQuery have not seemed to apply this? Possibly the syntax we are trying to use is incorrect.
next() can only select elements with an ID or Class - Not just a naked dom element as expected.
Instead use. > means select first level decends only.
$('body > div').hide();
But this gives the exact same result
$('body').children('div').hide();
But,
Next
$('body + div').hide();
and
Previous
$('body ~ div').hide();
Do not seem to work as expected? But jQuery use it as example for CSS selection...
Possibly there is a complex syntax to achieve this but I could not figure it out...