Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am refactoring old code to ES6 to not use Jquery:
Target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
However, I am getting a lint error:
ERROR: Unexpected string concatenation. [prefer-template]
Problem is, that inside of a data attribute selector, templates are not recognized.
const slice = this.hash.slice(1);
target = target.length ? target : $('[name="${slice}"]');
It will say
ERROR: 'slice' is assigned a value but never used.
Any help would be appreciated.
You need to use backticks instead of quotation marks: https://developers.google.com/web/updates/2015/01/ES6-Template-Strings
$(`[name="${slice}"]`)
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
js code :
...
let wr = $('div[class="topstory-content-wrapper last"]');
console.log(wr.html());
...
error: throw new SyntaxError("Malformed attribute selector: " + selector);
^
SyntaxError: Malformed attribute selector: class = topstory-content-wrapper last
Try to write your selector in the next way:
const wr = $('div.topstory-content-wrapper.last');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
if (!AlreadyReadExternalFile ("T:\PRINT SHOP\WebCRD Templates\Mailing Labels\Office Address")
{
ExternalData=new ExternalDataFileEx(LookupFile, "T:\PRINT SHOP\WebCRD Templates\Mailing Labels\Office Address,");
AlreadyReadExternalFile = true;
if (!ExternalData.valid)
{
var Message = "External file NOT found: " + LookupFile;
Print(Message);
}
else
{
var Message = "External file found: " + LookupFile;
Print(Message);
}
I have no knowledge of writing code. I was told to replace a few items which I did and now the code doesn't seem to work. Can someone please direct me to what I'm missing.
First line should be this
if (!AlreadyReadExternalFile ("T:\PRINT SHOP\WebCRD Templates\Mailing Labels\Office Address"))
You were missing the closing parenthesis to the if statement. The first line has two opening parentheses which must be closed.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Can someone please explain why this code isn't working?
(it has been simplified for this example)
$(document).ready(function () {
var test = 'broken';
test = test.replace('broken','working');
console.log(test); // working
var field = $('[for="tournament_name"]').html();
console.log(field); // Tournament Name:
console.log(typeof field); // string
field = field.relpace(':',''); // Uncaught TypeError: undefined is not a function
});
I don't understand why it is saying replace() is undefined?
I did read through the docs, what am I missing here?
Maybe it's a typo:
relpace --> replace
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to replace the src of an tag with another path. This works perfectly well:
var tempDocId = 'someId';
$('#documents' + that.ticketId).append('<img id="'+tempDocId+'" src="/img/support/pdf_icon.jpg">');
but the following code gives one of those "image not found" icons ():
var tempDocId = 'someId';
$('#documents' + that.ticketId).append('<img id="'+tempDocId+'" src="/img/support/loading.jpg">');
$('#tempDocId').attr("src", "/img/support/pdf_icon.jpg");
Does anybody know what I'm doing wrong here? All tips are welcome!
because you are looking for id="tempDocId", not the one you generated.
$('#tempDocId').attr("src", "/img/support/pdf_icon.jpg");
needs to be
$('#' + tempDocId).attr("src", "/img/support/pdf_icon.jpg");
so you are not replacing the source. My guess is that your loading image is not valid.
Because $('#tempDocId') doesn't exist. tempDocId is a variable, so try:
$('#' + tempDocId).attr('src', '/img/support/pdf_icon.jpg');
var tempDocId = 'doc' + Math.random().toString().substr(2);
var $img = $('<img id="'+tempDocId+'" src="/img/support/loading.jpg">');
$img.appendTo('#documents' + that.ticketId);
$img.attr('src', '/img/support/pdf_icon.jpg');
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want to append this to my DOM for every 'answer_' in my DB.
.append('<span>')
.text(format_date(answer_.LastModifiedDate))
But .LastModifiedDate won't always exist. Can I check for .LastModifiedDate in the text field? Maybe like this?
.append('<span>')
.text((answer_.LastModifiedDate) ? format_date(answer_.LastModifiedDate) : '')
Which doesn't work...
EDIT
I was stupidly checking for answer_.LastModifiedDate, instead of just answer.
So the following line works. Thanks for all the responses!
.append('<span>')
.text((answer_) ? format_date(answer_.LastModifiedDate) : '')
Of course that works. Ternary operators work anywhere you could normally place a variable. They evaluate to a value, just as if you used a string literal.
As #FreeAsInBeer pointed out, ternary works everywhere.
The only problem with your code is that you can't just use a (maybe) non-existant value as a boolean to check whether it is defined or not; How would you check if a variable holding "false" exists?
Instead you need to check the variables type:
.text(typeof answer_.LastModifiedDate !== 'undefined' ? format_date(answer_.LastModifiedDate) : '')
I was stupidly checking for answer_.LastModifiedDate, instead of just answer. So the following line works. Thanks for all the responses!
.append('<span>')
.text((answer_) ? format_date(answer_.LastModifiedDate) : '')