How to check attr class for string? - jquery-selectors

How to check attr class for string?
E.G.
HTML:
<p class="p_header"></p>
How to check that 'p' has in it's class '_header'string?
Any suggestions much appreciated.

$("p[class$='_header']")
OR
$("p[class*='_header']")

Use ......className.indexOf('_header') != -1
Do you need more details than that?

If you wanna check for a string within a p's class, you may use a simple search.
Say you have your 'p' inside a div.
$('#your_div p').first().attr('class').search("_header")
This returns -1 if false or no match found, &
index if true or match found.
OR you can directly access your 'p' using other answers submitted here.

Related

How to take integer input from user in dart

i am new in dart and just want to know how to take integer input from user in dart with null safety. i found out a way to take number input from dart which is:
String? chossenNumber = stdin. readLineSync();
if(chossenNumber !=null)
{
int number = int.parse(chossenNumber);
}
but i am unable to use number variable outside of the scope. Please tell me a way to solve this issue.
You can define the variable at the top of the class and initialize it here so you will be able to use it everywhere in the class
The solution of it very simple just take input of number as String i.e
String? chossenNumber = stdin. readLineSync();
and when you want to use this variable parse it to the 'int' i.e
if(int.parse(chossenNumber) <100)
{
print("Your Statement");
}

Swifty way of naming a boolean property

1.
According to the swift API design guidelines, a boolean property should read as assertions

> Uses of Boolean methods and properties should read as assertions about
the receiver when the use is nonmutating,
e.g. x.isEmpty, line1.intersects(line2).
2.
I would like to make a computed property of which type is Boolean to the existing data type.
Here is a simplified version of my code:
struct State {
var authorID: String
var myID: String
var `XXX`: Bool {
return myID == authorID
}
}
I want the property XXX to stand for whether I am author or not.
I firstly came up with the names like authorIsMe, iAmAuthor, isAuthorMe, etc. but realized that it didn’t read as assertions about the receiver.
So, what name do you think fit best for XXX? Any idea will be appreciated.
Thank you
(Please do not consider inlining the expression myID == authorID because in the original code, it is not short as above so I need the computed property)
amITheAuthor is the best property name according to me as it will clearly throw the answer & its means of use , its a suggestion you can use this as well.

How to negate class selector in Cytoscape.js?

I want to select all elements that do not have the class "myclass". How can I do that in Cytoscape.js?
According to http://js.cytoscape.org/#selectors/data, "[^name] Matches elements if the specified data attribute is not defined", however a class is not a data attribute and ^.myclass does not work, neither does :not(.myclass).
The error is The selector :not(.myclass) is invalid.
Is there a way to negate classes?
If you want to get the negative class selector, you can do this:
cy.elements().not(cy.$('.yourClass'));
// in more detail
var allElements = cy.elements(); // get all elements
var negators = cy.$('.yourClass'); // get all elements with the class to negate
var result = allElements.not(negators); // gets the difference between the two collections
If you really want to achieve this by using selectors only, then you might add a data field to each element which has myclass (this can be done while adding the class), and then use [^myclass]

Finding partial attribute value in Katalon

Trying to find a partial attribute value. Full value is no problem.
I have h1 class="a b c" and want to find out, whether this h1 has a as a class attribute.
Trying WebUI.verifyMatch(findTestObject('mytest/mytest-h1'),'a', 'a.*', false, FailureHandling.STOP_ON_FAILURE) and fails on finding.
Also answered via this Katalon Forum post (Apologies if the link is broken, in the future).
As per Mate Mrše's answer you can also try the following:
def attribute = WebUI.getAttribute(findTestObject('mytest/mytest-h1'), 'class')
boolean doesAttributeExist = attribute.contains('a')
if (!doesAttributeExist) {
// Add some logic/interaction
}
Since you added FailureHandling.STOP_ON_FAILURE the test will fail regardless of the condition.
Should you want the test to continue rather use FailureHandling.OPTIONAL
Try this:
def attribute = WebUI.getAttribute(findTestObject('mytest/mytest-h1'), 'class')
assert attribute.contains('a ')
Alternatively, create an object using the CSS class as the locator and verify the element exists:
assert WebUI.verifyElementClickable(findTestObject('mytest/mytest-h1-a')) == true

jQuery not selector with class match

How can I use jQuery to select all div elements that do not contain a class starting with the string 'upper' and do not contain a class starting with the string 'lower'. I tried the following couple of examples with no success:
$('div:not([class^=upper])').filter(':not([class^=lower])')
and
$('div').not('[class^=upper])').not('[class^=lower])')
Please advise...
This is a bit verbose, but it should do the trick -
$('div').filter(function() {
return $(this).attr("class").substring(0,5).toLowerCase() != 'upper' && $(this).attr("class").substring(0,5).toLowerCase() != 'lower'
})
You have to quote the string values in the comparison. In either of your examples above, replace lower with "lower". Do the same for upper.
Try this :not selector
$('div:not([class^=upper,class^=lower])');