setAttribute is undefined ,why? - function

This is my code follow:
[in html]```
```
[in css]```
.myclass {
width:50%;
}```
[in js] function changewidth() { let mynodes = document.getElementsByClassName('.myclass'); mynodes.setAttribute('width','100%'); }
then, when this function be run, it display:
Uncaught TypeError: Cannot read properties of undefined, when reading 'setAttribute'
what happen and how to correct ?
thanks

The error says that the myNodes variable is undefined meaning JavaScript cant find it anywhere because it doesn't exist.
Remove the dot(.) in
document.getElementsByClassName('.myclass')
It should be
document.getElementsByClassName('myclass')

Related

Uncaught TypeError: Cannot read properties of undefined (reading 'quote') at XMLHttpRequest.xhr.onload

can anyone tell me what i'm doing wrong?
document.getElementById('output').innerHTML = `
"${quotes[randomNum].quote}" - ${quotes[randomNum].character} <br>
${quotes[randomNum].pic}
`;
}
}
i didn't think I need to define quote because its in my json

Uncaught Error: Undefined constant "image"

I've an error when i execute the API JSON :
This is my code :
$image = get_the_post_thumbnail_url($post);
if (!image) {
$image = "";
}
And the error :
Uncaught Error: Undefined constant "image" in C:\xampp\htdocs\app\wp-content\themes\twentytwenty\functions.php:873
thx
There is an issue in this line.
if (!image) {
.. it should be.
if (!$image) {
It is a weird logic though because it says that when the $image is undefined or empty, empty it or assign a blank string literal to it.

VueJS search filter error: cannot ready 'search' of undefined

I'm building an app to consume a json and list it with a search filter input and other stuff.
I've already tried to create the function but it didn't work.
Codesandbox URL
https://codesandbox.io/s/vue-template-7iev3?fontsize=14
search: "",
Its showing "TypeError: Cannot read property 'search' of undefined" but its defined
TypeError: Cannot read property 'search' of undefined" doesn't mean that "search" is undefined but the parent object is. In your case, "this.search", this is undefined in your callback. You should use "self.search" because you already defined it or just change your syntax into:
computed: {
produtoFiltrado: function() {
return this.produtos.filter((cust) => {
return cust.nome.match(this.search);
});
}
}
Arrow functions doens't bind their "this" to their context so you can access your vue methods, props, data etc. using this without any problems
To avoid "TypeError: Cannot read property 'includes' of null" problem, better to add line before return
computed: {
filteredItems() {
return this.customers.filter(item => {
return (item.title || '').toLowerCase().indexOf((this.search || '').toLowerCase()) > -1
})
}}
(this.search || '') will do trick..

Hel­p with actionscript 3 syntax

I would like your help here, this is my actionscript3 code.
Everytime I compile I get error.
Line 1537 1073: Syntax error: expecting a catch or a finally clause.
This is the code
{
try
{
}
_loc_3.badge.gotoAndStop(param1.split(":")[2]);
}
And the second error
{
try
{
}
_loc_3.badge.gotoAndStop(param1.split(":")[2]);
}
The second error says:
Line 1537 1084: Syntax error: expecting rightbrace before semicolon.
Could anyone help me here, thanks in advance.
UPDATE: After I add a right brace before the semicolon it gives more errors.
The first error is really explicit, you need a catch block. The empty try block is useless.
The syntax found on a website.
try {
//Your code
}
catch(e:Error) { // Error handling
trace("Error found: " + e);
}
//Optional
finally {
// Closing connection for example.
}
Website reference in french
A try cannot be used without a catch. the idea there is lets try this piece of code and if we run into any problems stop and execute the content of whatever is in the catch. the finally is used for executing code that you want to run regardless of whether the try or catch gets executed.
in the first error:
you are just missing a catch. also maybe include some code into the try statement, otherwise its pointless to use.
example:
try
{
//try to feed my dog
feedDog();
}
//if some error occurs in feedDog() then the catch will be called
//if you want to catch specific exceptions
//then specify its type instead of Exception
catch (Exception e)
{
trace("unable to feed dog");
}
//this will execute whether the dog was fed successfully or not
finally
{
trace("leave");
}
with the second error: you are probably missing a '}' somewhere in that function. Indent your code so that these will become clearly visible to you and you can match every '{' with its corresponding '}'

Read single second level JSON entry with Ionic

I've got this JSON file that I'm trying to parse the second level off. But it seems to fail.
{
"error":false,
"accessToken":"xxx",
"accountId":"xxx",
"account":[
{
"error":false,
"id":"2",,
"username":"Username"
}]
}
Here's the Ionic code
return $http.post(SERVER.apiUrl + SERVER.apiLogin,
{username: "username",password: "password"})
.success(function(data){
o.setSession(data.accountId, data.accessToken, data.account[0]["username"]);
});
Error
TypeError: Cannot read property '0' of undefined
at services.js:103
at ionic.bundle.js:17151
at processQueue (ionic.bundle.js:20962)
at ionic.bundle.js:20978
at Scope.$eval (ionic.bundle.js:22178)
at Scope.$digest (ionic.bundle.js:21994)
at Scope.$apply (ionic.bundle.js:22282)
at done (ionic.bundle.js:17439)
at completeRequest (ionic.bundle.js:17629)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:17570)
i have also tried with
data.account.username
and
data.account[0].username
Can anybody give a quick advice?
Best regards
do not understand why it does not work for you, I tried it and does not give me problems.
Although at least here, you put two commas after ID
data.account[0]["username"] Is Ok
 
{
"error":false,
"accessToken":"xxx",
"accountId":"xxx",
"account":[
{
"error":false,
"id":"2",, <-- ERROR
"username":"Username"
}]
}