This question already has answers here:
How do I concatenate a string with a variable?
(5 answers)
Closed 3 years ago.
This is basic ,
I can show or hide a class with :
$('.blink').show();
but I would like to do the same with a parameter so
var a = "blink";
$(a).show();
will not work obviously and I couldn't find the keywords to look for this in google.
You need to append a dot when you use that variable so that the $ will consider it as a class selector:
var a = "blink";
$('.'+a).show();
Related
This question already has answers here:
Finding elements by class name with Selenium in Python
(6 answers)
Closed 2 years ago.
try:
main = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "main"))
)
articles = main.find_elements_by_tag_name("article")
for article in articles:
header = article.find_element_class_name("entry-title")
print(header.text)
finally:
driver.quit()
It shows the error as:
AttributeError: 'WebElement' object has no attribute 'find_element_class_name'
It should be find_element_by_class_name and find_elements_by_class_name for a list of elements with the given class name
This question already has answers here:
How to update (append to) an href in jquery?
(4 answers)
Append URL parameter to href with JavaScript
(2 answers)
How to append to an anchor's href attribute with JavaScript but not affect query string?
(3 answers)
Closed 2 years ago.
I want to change all the labels links and have a specific number to access it in blogger using JavaScript automatically
An illustrative example
../search/label/Label_name and add max-results=7 after "label name"
how i can do it .. i want help and thank you.
Something like this should do the trick. If you have further questions feel free to ask them :)
var x = document.querySelectorAll("a");
x.forEach(function(element){
var link = element.href;
console.log(link)
element.href = link + "?max-results=7";
console.log(element.href);
});
Example link
This question already has answers here:
How to add a class to a given element?
(28 answers)
Closed 7 years ago.
Is there a way to add a second class to an HTML tag using javascript? For example, say you had the element <p class="a"> and you wanted to add class="b". If you used document.getElementByClassName("a").class = "b" that would remove class "a". Is there a way to have both in the same element?
document.getElementsByClassName("a")[0].className += " b"
First of all, the method is named getElementsByClassName, plural. You need to refer to a specific element in the collection that it returns, via a zero-based index.
And you need the space before b here, so that you don’t end up with ab, but a b.
Try this one here:
document.getElementByClassName("a").className += " b"
Got it from here: How do I add a class to a given element?
This question already has answers here:
How to find if div with specific id exists in jQuery?
(10 answers)
Closed 7 years ago.
I have some DIVs with IDs like 'abc_chosen', 'danger_chosen', etc.
I would like to delete all DIVs when their IDs contain the string '_chosen'.
How can I do that?
Try this:
$('div[id$="_chosen"]').remove();
$ here will check if _chosen is at the end of id.
Thanks to #evolutionxbox:
If you want to check if id contain _chosen anywhere(not at the end)
$('[id*="_chosen"]').remove();
Docs: https://api.jquery.com/attribute-ends-with-selector/
This question already has answers here:
How do I remove a property from a JavaScript object?
(37 answers)
Closed 3 years ago.
How can I remove an item from a JavaScript object?
Like this:
var test = {'red':'#FF0000', 'blue':'#0000FF'};
test.remove('blue');
var test = {'red':'#FF0000', 'blue':'#0000FF'};
delete test.blue; // or use => delete test['blue'];
console.log(test);
this deletes test.blue