How can I address all inner elements of a div, if I don't know what they are?
<div class="outer">
<p>
Hi, Mark!
</p>
<div class="inner"></div>
<div>
Say, in this case I want to get everything in the outer div and get maybe an HTMLcollection or an array of a, p, div.inner. Though I'm not supposed to know they are a, p and div.
* is the "select-all" (wildcard) selector
.outer *
Related
In the following JSX
Why is there a double !
{!! count && <div className={'styles.info'}>{`did this ${count}`}</div>}
You don't want the space between !! and count. They should be together like so: !!count.
Like the comment said, it is coercing the value to a boolean. If count is a falsey value, say 0, it would still be rendered by React. Using !! to coerce 0 to false, would guarantee that 0 is never rendered.
I'm trying to write an xpath that selects all the elements that contains text which ends with numbers and surrounded by braces. The numbers can be anything and it can be of any number of digits. Is this possible in XPath1.0? I cannot use regex as it is not allowed in XPath1.0
<div class = '12345' >
<div class = '98231'>I want this (101)</div>
<div class = '98232'>I don't want this 101</div>
<div class = '98233'>I want this (1)</div>
<div class = '98234'>I don't want this (10A1)</div>
</div>
In XPath-1.0 you cannot use RegEx'es.
But you can use the fn:number() function to check if a given string could be a valid number with the fn:boolean function:
/div/div[boolean(number(substring-before(substring-after(.,'('),')')))]
Obviously, this does only work if there are no other brackets in the string. And it doesn't check if the number in brackets is at the end of the string. To add this further restriction, change the expression to
/div/div[not(boolean(string(normalize-space(substring-after(.,')'))))) and boolean(number(substring-before(substring-after(.,'('),')')))]
This adds a further predicate to check if there are characters other than whitespace after the ). Leading and trailing whitespace between the brackets is automatically removed by the fn:number() function.
Try following xpath:
//div//div[text() and contains(text(),'(') and contains(text(),')')]
Is it possible to set ng-repeat to repeat items X from an array 5 times, then add item Y, and continue repeating X.
The desired result would be:
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
<div>{{y.item}}</div>
<div>{{x.item}}</div>
<div>{{x.item}}</div>
...
I hope that explains it. Y item could also be a div whose contents do not come from said array.
You may doing something like:
<div ng-repeat-start="x in items">
{{x.item}}
</div>
<div ng-repeat-end ng-if="$index === 5">
{{y.item}}
</div>
I am having the following set up inside an ng-repeat directive:
<span ng-model="d.attr3">
{{d.attr2 - d.attr1}}
</span>
d is the variable used inside ng-repeat.
My issue is that I expect d.attr3 to hold the value of the expression inside span tag. However, it holds the expression NaN.
Note that I have converted the d.attr1 and d.attr2 values to integers - In fact, the expression evaluates correctly but it is not bound to the scope - how do I get d.attr3 to hold the value of the expression?
<span ng-init="d.attr3 = d.attr2 - d.attr1">
{{d.attr3}}
</span>
I have this array:
val lines: Array[LineSprite] = new Array[LineSprite](26)
And I want to be able to select everything in it at once. How do I go about doing this?
I know selecting one element in the array would look like this:
lines(0)
But how do I select all at once?
That array has 26 elements. I need to change the color of each element. To do that for one element I would do it like this:
lines(0).setColor(Color.blue)
Instead of having one of those pieces of code for each element, how can I do it all at once?
Thanks
I guess by 'select' you mean apply the same operation to all. In that case, you should use the foreach method available on all Traversables, like :
lines.foreach( _.setColor(Color.blue))
It is usually done with either foreach method (if you're performing some side effects, like setting color, printing or something else) or map method (if you care about result):
lines.foreach(l => l.setColor(Color.blue))
val squares = List(1,2,3,4).map(n => n * n)
// squares are now List(1,4,9,16)
// note that line below is wrong
val squares = List(1,2,3,4).foreach(n => n * n)
// squares now is Unit (aka void) because foreach doesn't return anything
Those methods defined for literally every build-in collection and arrays.