How to use attr in elements within an array? [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
So, I have an array with 200 items called "icone", and when I use this code:
icone.attr('src', 'img/known.svg');
All items change according to what is in the code.
But how do I do if I want to change only 1 of the items in this array, and not all 200?
I tried with:
icone[0].attr('src', 'img/known.svg');
But the console returned "icone[0].attr is not a function".
Any ideas on how to make this work?
Thanks!

If it is absolutely necessary to use jQuery in this case. You can do this:
$(icone[0]).attr('src', 'img/known.svg');
In case it is not, you can do it as the other answers say.

Once you do icone[0], you're dealing with a raw node, not a jQuery "wrapper." That raw element does not have an .attr function.
As Ouroborus suggests, just set the attribute directly by doing icone[0].src = ....
(If Ouroborus submits an answer in addition to their comment, you should mark it as accepted, not this answer. I just wanted to explain why what you're doing doesn't work.)
EDIT: Interestingly, icone.first().attr(...) does work, because it does wrap the first element with a jQuery wrapper.

Related

JavaScript, what is "binde" means, not "bind"? document.binde.tagname...? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have in my JS code, some lines with binde, what is it? Why is it working and what does it mean?
On example with, type="checkbox":
if (document.binde.nameofthecheckbox.checked)
{
//...its true whens checked and do the code
}
or
somevar = document.binde.somehtmltagname.value;
somevar gets the value of "somehtmltagname"
No one can answer me, I only heard "never seen something like that before". I would be happy to know what it is, and not only using it because it works.
It is not well known, but document might define HTML elements with id specified as document[HTMLElement.ID] as such, if there is an <input id="binde"> on the page, it will point to that.
If not, try logging it:
console.log(document.binde)

Javascript is returning empty value [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This may seem as a dumb question, but I just can't figure out, what am I doing wrong?
I have a HTML textarea which always contains one simple sentence. What am I trying to achieve is to load this sentence into JS variable with the help of ".value;"
But when I try to print out the variable, it's always empty - Screenshot from the console
Can you please tell me, what am I doing wrong, or at least point me the right direction?
Thanks in advance!
Textareas have a different behavior that inputs. Their value is stored inside the opening and the closing tags.
Here is an example :
alert(document.getElementById('textarea').value);
<textarea id="textarea">I am the value !</textarea>
Also next time, please include your code and the result as text, not as an image.
Use this:
alert(document.getElementById('separator').value)
<textarea id="separator">Lorem ipsum</textarea>
value for a textarea is the value enclosed between the tags <textarea></textarea. In your case that is ''. Hence, you get an empty string.
You 'd be better off if you included some text between the tags. I am sure you will get the result you need then.

If statement not working properly in form validation [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I've would like to make a really simple form validation is JS.
I've created a function with if statements inside,while everything is ok it should display nothing and when something is not right (number in a name input for e.g)
a message under a certain input should be displayed.Right now it sometimes work,sometimes not.
If anybody could look at my code and tell me what's wrong would be really helpful
Here's my live version
Here's the code
You are using name="name-surname" twice (in two different input tags), which prevents the values to be sent properly. Use the same values for name as the values for the IDs

How to retreive current test case name in nightwach [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I m working with balloon pop up which will invoke for currently running test case, I need to pass the current test case name to that balloon popup.I tried with browser.currentTest but it is returning [object, object]. Is there any other way of retrieving the current test case name,if so can someone help me in retrieving the current test case name. Thanks in advance.
Try
browser.currentTest.module
In nightwatch, you have access to the name of the currentTest using .module. It's not in the docs, it just came up by logging
var keys = Object.keys(client.currentTest)
to the console like:
console.log(keys)
from the base test class. Adding that to the prototype isn't even necessary as it's available in any test. "module" is a property of the Test object in Nightwatch.
Also note that, from experience, the seemingly inaptly named browser.currentTest.name is not what you want. It's an array of numbers whose purpose I have yet to deduce...

JS Can not use click function after append [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I add my TRIGGER DIV A over $(".DIVB").html(data); from a AJAx Responsebut when i now want to trigger some code over the $(".TRIGGER DIV A").click(function() it isnt working. Can someone explain me why ? And is there a Way to fix this or is there a working arround ?
It looks like you're using jQuery's .click(). If HTML is added dynamically to the DOM, you need to bind the click event to the element after it has been added. Otherwise, when $(".TRIGGER DIV A").click(handler) runs and jQuery looks for the element to bind, it isn't able to find it.
You may consider using .delegate() instead. This ensures that the event is bound to all elements relevant to the given selector regardless of when it is added to the DOM. You can find the documentation for usage here: http://api.jquery.com/delegate/

Categories