Is there another way to write line 6

Is there another way to write line 6

Content Index :

Is there another way to write line 6
Tag : javascript , By : ikey
Date : January 11 2021, 05:14 PM

To fix the issue you can do You can use Template literals but as @msg noted that's not jQuery specific.
        if ($(window).scrollTop() > $(this).offset().top){
            var blockID = $(this).attr("id");
            $("nav a").removeClass("active");
            $(`nav a[data-scroll="${blockID }"]`).addClass("active");

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How can I read line by line an HTML file and return document.write() for each line with Javascript?

Tag : javascript , By : user123284
Date : March 29 2020, 07:55 AM
wish of those help Please explain WHY youneed document.write - what is the actual reason for this? jQuery can easily grab content and insert on a page if the content comes from the same site as the page you want to assemble it on
For example
$(function() {
  var $body = $("body");
  $.get("header.html",function(data) {
  $.get("footer.html",function(data) {
<!DOCTYPE html>
    <link rel="stylesheet" type="text/css" href="style.css">
    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript" src="include.js"></script>
<!-- CONTENT -->
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<title>Test header footer insertion without jQuery</title>
var pages = [
var req,cnt = pages.length;
function ajax_fragment(){
    cnt--; if (cnt<0) return;
    if (!req) { // singleton
      if (window.XMLHttpRequest){
          req=new XMLHttpRequest(); 
      } else{ 
          req=new ActiveXObject("Microsoft.XMLHTTP"); 

        if(req.readyState==4 && req.status==200){
            var tempDiv = document.createElement("div");       
            tempDiv.innerHTML = req.responseText; 
            var fragment = document.createDocumentFragment();  
            var tag = document.getElementsByTagName(pages[cnt].tag)[0]; 
            if (pages[cnt].where=="before") tag.insertBefore(fragment, tag.firstChild);
            else tag.appendChild(fragment);
            ajax_fragment(); // next 
window.onload=function() {
<div id="content">Here is some content</div>

Code's write either 1 line too many, or 1 line short of what's it supposed to write

Tag : vb.net , By : Ted Leung
Date : March 29 2020, 07:55 AM
like below fixes the issue I recently coded an app which creates a random password out of characters taken from the alphabet, then encrypt them using the Rijndael algorithm and writes them to a .txt file. , Try something like this out instead:
    Dim lines As New List(Of String)
    For i As Integer = lines.Count - 1 To 0 Step -1
        If lines(i) = "" Then
        End If

    If passName = "" Then
        lines.Add(passName & " " & cryptPass)
    End If

    System.IO.File.WriteAllLines(fileLoc, lines.ToArray)

Read line, seperate words by delimiter, write each word on new line, then move on to the next line

Tag : chash , By : brennen
Date : March 29 2020, 07:55 AM
This might help you You need to move line = sr.ReadLine(); out for the foreach loop. Right now it is reading a new line for each string in the first line, which consumes the rest of the input.
It should be immediately after the foreach loop, but still within the while loop.

Write a line to a file, but also write previous line if it matches a pattern and exists

Tag : bash , By : user90210
Date : March 29 2020, 07:55 AM
around this issue You can parse the file fairly easily with your function in bash. The key is not to worry about looking for the tag lines. Simply look for Scenario, having checked/saved the previous tag line each iteration in some variable like tag. When Scenario is found, check if tag exists. If so, write the tagline held in tag before Scenario and then continue with normal writing of output.

function writeToTestFile {
    [ -z "$1" ] && {    ## validate input
        printf "%s() error: insufficient input.\n" "$FUNCNAME"
        return 1
    [ -r "$1" ] || {    ## validate file readable
        printf "%s() error: file not readable '%s'\n" "$FUNCNAME" "$1"
        return 1
    local tag=""    ## use local declarations
    local line=""
    local num=""
    local fname=""
    while IFS='' read -r line || [ -n "$line" ]; do
        if [ "${line// */}" = "Scenario" ]; then    ## check Scenario
            num="${line/Scenario /}"                ## parse num
            fname="File_${num%:}.txt"               ## parse fname
            :> "$fname"                             ## truncate fname
            [ -n "$tag" ] && printf "%s\n" "$tag" > "$fname"  ## tagline
            printf "%s\n" "$line" >> "$fname"       ## write Scenario line
        fi  ## write normal lines & update tagline
        [ "${line:0:1}" = " " ] && printf "%s\n" "$line" >> "$fname"
        [ "${line:0:1}" = "@" ] && tag="$line" || tag=
    done < "$1"
    return 0

writeToTestFile "$1"
$ cat tagfile.txt
Scenario 1:
   Do thing 1
   Do thing 2
Scenario 2:
   Do thing 1
   Do thing 3
Scenario 3:
   Do thing 1
   Don't do thing 4
$ bash tags.sh tagfile.txt
$ cat File_1.txt
Scenario 1:
   Do thing 1
   Do thing 2

$ cat File_2.txt
Scenario 2:
   Do thing 1
   Do thing 3

$ cat File_3.txt
Scenario 3:
   Do thing 1
   Don't do thing 4

How to write a batch script to read a text file line by line,match it with a regex and then edit the line in the same fi

Tag : batch-file , By : SilverRuby
Date : March 29 2020, 07:55 AM
With these it helps Regular expression replaces are not possible with pure usage of Windows command line interpreter cmd.exe or the console applications installed with Windows. This would require usage of a scripting language/interpreter with support for regular expression replaces in files like PowerShell or JScript which would be most likely better choices for this task.
However, a pure batch file solution is also possible for this task as it can be seen on commented batch code below with lots of extra features.
@echo off
set "TempFile=
rem Is first parameter /? for getting help?
if "%~1" == "/?" goto ShowHelp

rem Is the batch file not started with any none empty parameter?
if not "%~1" == "" (
    rem Does the first parameter not consist of only digits 0-9?
    for /F "delims=0123456789" %%I in ("%~1") do goto ShowHelp

rem Is there also specified a second parameter?
if not "%~2" == "" (
    rem Is the second parameter neither enable nor disable (case-insensitive)?
    if /I not "%~2" == "disable" if /I not "%~2" == "enable" goto ShowHelp

rem Setup a local environment for this batch file.
setlocal EnableExtensions DisableDelayedExpansion

rem Define the name of the text file without or with path to modify.
rem Define the name of the temporary file needed to modify the file.
set "TextFile=TextFile.txt"
set "TempFile=%TEMP%\%~n0.tmp"

rem Does the text file to modify exist at all?
if not exist "%TextFile%" goto MissingFile

rem Was a task number specified on starting this batch file?
if not "%~1" == "" set "TaskNumber=%~1" & goto FindTask

rem Prompt the user for the task number and make sure that the user really
rem enters a number by verifying user input using a very secure method.
set "TaskNumber="
set /P "TaskNumber=Enter task number: "
if not defined TaskNumber goto PromptNumber
setlocal EnableDelayedExpansion
for /F "delims=0123456789" %%I in ("!TaskNumber!") do endlocal & goto PromptNumber

rem Does the file to modify contain the number at beginning of a
rem line as specified with first parameter and followed by a colon?
%SystemRoot%\System32\findstr.exe /B /L /M /C:"%TaskNumber%:" "%TextFile%" >nul 2>&1
if errorlevel 1 goto MissingNumber

rem Has the user specified the action to perform as second parameter.
if /I "%~2" == "enable"  set "TaskAction=1" & goto ModifyFile
if /I "%~2" == "disable" set "TaskAction=2" & goto ModifyFile

rem Prompt the user for the action to perform.
%SystemRoot%\System32\choice.exe /N /M "Press Y to enable or N to disable task: "
set "TaskAction=%ERRORLEVEL%"

rem Copy the file with ignoring empty lines and lines starting with a
rem semicolon to temporary file with modifying all lines starting with
rem the specified task number according to specified action to perform.
rem But delete the temporary file before if existing by chance.
del "%TempFile%" 2>nul
set "FileModified="
for /F "usebackq tokens=1* delims=:" %%I in ("%TextFile%") do (
    if not "%%I" == "%TaskNumber%" (
        echo %%I:%%J>>"%TempFile%"
    ) else (
        set "TextLine=%%I:%%J"
        call :ModifyLine

rem Was no line modified on copying all the lines to temporary file?
if not defined FileModified del "%TempFile%" & goto EndBatch

rem Move the temporary file over the text file to modify.
move /Y "%TempFile%" "%TextFile%" 2>nul

rem Was the text file overwritten by command MOVE?
if not errorlevel 1 goto EndBatch

rem Inform the user that the text file to modify could not be
rem modified because of being read-only or missing appropriate
rem NTFS permissions or a sharing access violation occurred.
del "%TempFile%"
for /F %%I in ("%TextFile%") do set "TextFile=%%~fI"
echo ERROR: "%TextFile%" could not be modifed.
echo Please make sure the file has not read-only attribute
echo set, is not opened in any application and you have
echo the necessary permissions to overwrite this file.
goto HaltBatch

rem This is a subroutine which modifies a line with right task
rem number according to action to perform and outputs this line
rem into the temporary file. It records also if the line needed
rem to be modified at all.
if %TaskAction% == 1 (
    if not "%TextLine:~-2%" == ":N" (
        set "TextLine=%TextLine%:N"
        set "FileModified=1"
) else (
    if "%TextLine:~-2%" == ":N" (
        set "TextLine=%TextLine:~0,-2%"
        set "FileModified=1"
>>"%TempFile%" echo %TextLine%
goto :EOF

rem Get name of file with full path which works also for not existing
rem file and inform the user about missing file to modify with full
rem path to see also where this batch file expected it on execution.
for /F %%I in ("%TextFile%") do set "TextFile=%%~fI"
echo ERROR: "%TextFile%" does not exist.
goto HaltBatch

rem The specified number does not exist in the file to modify
rem at beginning of a line. Inform the user about this error.
echo ERROR: %TaskNumber% not found in file "%TextFile%".
goto HaltBatch

echo Usage: %~nx0 [task] [disable ^| enable]
echo        task ...... number of the task to enable or disable.
echo        disable ... disable the specified task.
echo        enable .... enable the specified task.
echo %~nx0 can be also started without any parameter.
echo In this case the task number and the action to perform
echo can be entered during the execution of the batch file.


if defined TempFile endlocal
Related Posts Related QUESTIONS :
  • Direct native JavaScript or jQuery method to get containing block of an element
  • Dynamic JSON object to Html Table
  • How to send Id and file to same controller?
  • How to Make a jQuery Table Cell(td) clickable to Run a Function?
  • Prevent the duplicate function onchange event jQuery
  • Reactjs Input Upload doesn't return local URL
  • An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected
  • How to filter a JSON Array, with an eventListener input value at keyup
  • How to separate the different properties of filter in css?
  • Why dont work change event of bootstrap input spinner?
  • How to hide overflow text content in react
  • Cypress - how to find by text content?
  • How to setstate for the dynamic checkboxes in a loop in react?
  • Is display:none safe?
  • How to create a form to change part of a href url of a button?
  • Put many function inside function in Javascript
  • how to exit from loop after a ajax call
  • Do Angular Reactive Form Validator.min/max check Perform Type Conversions before checking the value?
  • How to Replace Text Within Script Tags Using JQuery
  • add variable to object if not undefined using short-hand
  • How can I effectively curve my items inside a list?
  • Add new record Keyboard Shortcut on Kendo Grid Mvc
  • Time and Date running on page
  • Looping through page links puppeteer doesn't return values from the newly loaded page
  • Problem with Navigator.geoLocation.getCurrentPosition not working
  • Trying to change the id of an element with Javascript
  • Embedded Schema Inserting Blank in Meteor using Collection2
  • avoid useEffect to render at first load?
  • Why is this CSS transition only working correctly on the some clicks? How to solve it?
  • Interpolated values does not reflect the latest values in an Angular app
  • Javascript classes define attribute in constructor or outside the class
  • How to block scroll event passing through to iframe until iframe is active?
  • What is the purpose of "constructor" method in javascript?
  • Stencil JS not working with non-default imports
  • Are frameworks misleadingly named for marketing purposes?
  • React <Redirect> after transition not working
  • How to send multiple parameters in a function using EJS
  • React conditional style on custom click
  • Push a block of information to an array X times based on an external variable
  • How do I populate dropdown with names, and values (numeric ids)?
  • How to apply styling to elements created with .insertAdjacentHtml method
  • Positioning key:value of an object
  • Referencing DOM Elements with React Hooks
  • TypeError: Method "getRange" of null when using multiple scripts (Libraries) in Google scripts
  • Why can't I check if an environment variable is undefined?
  • Is there a way to find what parts are the same between two strings?
  • Every change done with magicscroll and greensock get reset when I hit the bottom of the page
  • Fix a 'Cannot read property handleClick of undefined error' (and issues related to deleting an item from the DOM)
  • Answer to message if sent within a period of time
  • Enabling a button based on selected values
  • Get All possible matches between forward slashes
  • get the CSS maxWidth value of the parent javascript
  • Async function returning existing array as undefined
  • Using drop-down list to change multiple values in separate table cells
  • How to remove nested empty objects in JavaScript?
  • Convert value from text field to paragraph
  • Sorting a list based on instructions in Javascript
  • Post request doesn't work in NodeJS, OK with Request
  • How to make footer align to center in nested component scenario in React
  • fresh installed pwa does not show content
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com