WebStorm: can't catch with jQuery












1















I create a website with React.js with slider which use jQuery for autoscrolling. I have done it in the sandbox (Codepen.io), it works well. After I began to do it with "create-react-app" and WebStorm. What I have done:
In the command line I wrote:



"npm install create-react-app"
"npm install jquery"
"create-react-app my-app"


After that I have opened "my-app" with WebStorm 2018.2 (x86) and transferred into it all my code from the sandbox adding some "import" command. So the slider doesn't work now (it works like JavaScript code is absent).
I deleted the extra code. That's what's left:
JS code



import React from 'react';
import $ from 'jquery'

/*jshint esversion: 6 */
class App extends React.Component {
render() {
return <div><div className = "slider"><input type = "radio" name = "slides" id = "slide1" /><input type = "radio" name = "slides" id = "slide2" /><input type = "radio" name = "slides" id = "slide3" /><input type = "radio" name = "slides" id = "slide4" /><input type = "radio" name = "slides" id = "slide5" />
<input type = "radio" name = "slides" id = "slide6" /><div className = "captions"><div className = "c2" > Prediction 2 </div><div className = "c3"> Prediction 3 </div> <div className = "c4" > Prediction 4 </div> <div className = "c5" > Prediction 5 </div>
<div className = "c6" > Prediction 6 < /div></div></div> <div className = "controls" ><label htmlFor = "slide1" /><label htmlFor = "slide2" /><label htmlFor = "slide3" /><label htmlFor = "slide4" /><label htmlFor = "slide5" /><label htmlFor = "slide6" /></div></div>;
}
}

ReactDOM.render( <App/> , document.getElementById('root'));

//script for slider's autoscrolling

let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});


HTML



<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<meta charset="utf-8">
<title>React App</title>
</head>

<body>
<div id="root"></div>
</body>
</html>


In the console I see: jQuery.fn.init(0). What I should do to catch inputs?










share|improve this question




















  • 1





    Use document.ready(function(){...}).

    – connexo
    Nov 16 '18 at 7:43











  • Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

    – diesel94
    Nov 16 '18 at 9:54











  • Before, you were trying to access the DOM before it was fully parsed.

    – connexo
    Nov 16 '18 at 9:57
















1















I create a website with React.js with slider which use jQuery for autoscrolling. I have done it in the sandbox (Codepen.io), it works well. After I began to do it with "create-react-app" and WebStorm. What I have done:
In the command line I wrote:



"npm install create-react-app"
"npm install jquery"
"create-react-app my-app"


After that I have opened "my-app" with WebStorm 2018.2 (x86) and transferred into it all my code from the sandbox adding some "import" command. So the slider doesn't work now (it works like JavaScript code is absent).
I deleted the extra code. That's what's left:
JS code



import React from 'react';
import $ from 'jquery'

/*jshint esversion: 6 */
class App extends React.Component {
render() {
return <div><div className = "slider"><input type = "radio" name = "slides" id = "slide1" /><input type = "radio" name = "slides" id = "slide2" /><input type = "radio" name = "slides" id = "slide3" /><input type = "radio" name = "slides" id = "slide4" /><input type = "radio" name = "slides" id = "slide5" />
<input type = "radio" name = "slides" id = "slide6" /><div className = "captions"><div className = "c2" > Prediction 2 </div><div className = "c3"> Prediction 3 </div> <div className = "c4" > Prediction 4 </div> <div className = "c5" > Prediction 5 </div>
<div className = "c6" > Prediction 6 < /div></div></div> <div className = "controls" ><label htmlFor = "slide1" /><label htmlFor = "slide2" /><label htmlFor = "slide3" /><label htmlFor = "slide4" /><label htmlFor = "slide5" /><label htmlFor = "slide6" /></div></div>;
}
}

ReactDOM.render( <App/> , document.getElementById('root'));

//script for slider's autoscrolling

let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});


HTML



<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<meta charset="utf-8">
<title>React App</title>
</head>

<body>
<div id="root"></div>
</body>
</html>


In the console I see: jQuery.fn.init(0). What I should do to catch inputs?










share|improve this question




















  • 1





    Use document.ready(function(){...}).

    – connexo
    Nov 16 '18 at 7:43











  • Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

    – diesel94
    Nov 16 '18 at 9:54











  • Before, you were trying to access the DOM before it was fully parsed.

    – connexo
    Nov 16 '18 at 9:57














1












1








1








I create a website with React.js with slider which use jQuery for autoscrolling. I have done it in the sandbox (Codepen.io), it works well. After I began to do it with "create-react-app" and WebStorm. What I have done:
In the command line I wrote:



"npm install create-react-app"
"npm install jquery"
"create-react-app my-app"


After that I have opened "my-app" with WebStorm 2018.2 (x86) and transferred into it all my code from the sandbox adding some "import" command. So the slider doesn't work now (it works like JavaScript code is absent).
I deleted the extra code. That's what's left:
JS code



import React from 'react';
import $ from 'jquery'

/*jshint esversion: 6 */
class App extends React.Component {
render() {
return <div><div className = "slider"><input type = "radio" name = "slides" id = "slide1" /><input type = "radio" name = "slides" id = "slide2" /><input type = "radio" name = "slides" id = "slide3" /><input type = "radio" name = "slides" id = "slide4" /><input type = "radio" name = "slides" id = "slide5" />
<input type = "radio" name = "slides" id = "slide6" /><div className = "captions"><div className = "c2" > Prediction 2 </div><div className = "c3"> Prediction 3 </div> <div className = "c4" > Prediction 4 </div> <div className = "c5" > Prediction 5 </div>
<div className = "c6" > Prediction 6 < /div></div></div> <div className = "controls" ><label htmlFor = "slide1" /><label htmlFor = "slide2" /><label htmlFor = "slide3" /><label htmlFor = "slide4" /><label htmlFor = "slide5" /><label htmlFor = "slide6" /></div></div>;
}
}

ReactDOM.render( <App/> , document.getElementById('root'));

//script for slider's autoscrolling

let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});


HTML



<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<meta charset="utf-8">
<title>React App</title>
</head>

<body>
<div id="root"></div>
</body>
</html>


In the console I see: jQuery.fn.init(0). What I should do to catch inputs?










share|improve this question
















I create a website with React.js with slider which use jQuery for autoscrolling. I have done it in the sandbox (Codepen.io), it works well. After I began to do it with "create-react-app" and WebStorm. What I have done:
In the command line I wrote:



"npm install create-react-app"
"npm install jquery"
"create-react-app my-app"


After that I have opened "my-app" with WebStorm 2018.2 (x86) and transferred into it all my code from the sandbox adding some "import" command. So the slider doesn't work now (it works like JavaScript code is absent).
I deleted the extra code. That's what's left:
JS code



import React from 'react';
import $ from 'jquery'

/*jshint esversion: 6 */
class App extends React.Component {
render() {
return <div><div className = "slider"><input type = "radio" name = "slides" id = "slide1" /><input type = "radio" name = "slides" id = "slide2" /><input type = "radio" name = "slides" id = "slide3" /><input type = "radio" name = "slides" id = "slide4" /><input type = "radio" name = "slides" id = "slide5" />
<input type = "radio" name = "slides" id = "slide6" /><div className = "captions"><div className = "c2" > Prediction 2 </div><div className = "c3"> Prediction 3 </div> <div className = "c4" > Prediction 4 </div> <div className = "c5" > Prediction 5 </div>
<div className = "c6" > Prediction 6 < /div></div></div> <div className = "controls" ><label htmlFor = "slide1" /><label htmlFor = "slide2" /><label htmlFor = "slide3" /><label htmlFor = "slide4" /><label htmlFor = "slide5" /><label htmlFor = "slide6" /></div></div>;
}
}

ReactDOM.render( <App/> , document.getElementById('root'));

//script for slider's autoscrolling

let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});


HTML



<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<meta charset="utf-8">
<title>React App</title>
</head>

<body>
<div id="root"></div>
</body>
</html>


In the console I see: jQuery.fn.init(0). What I should do to catch inputs?







javascript jquery html webstorm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 16:25









LazyOne

110k21244266




110k21244266










asked Nov 16 '18 at 7:40









diesel94diesel94

648




648








  • 1





    Use document.ready(function(){...}).

    – connexo
    Nov 16 '18 at 7:43











  • Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

    – diesel94
    Nov 16 '18 at 9:54











  • Before, you were trying to access the DOM before it was fully parsed.

    – connexo
    Nov 16 '18 at 9:57














  • 1





    Use document.ready(function(){...}).

    – connexo
    Nov 16 '18 at 7:43











  • Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

    – diesel94
    Nov 16 '18 at 9:54











  • Before, you were trying to access the DOM before it was fully parsed.

    – connexo
    Nov 16 '18 at 9:57








1




1





Use document.ready(function(){...}).

– connexo
Nov 16 '18 at 7:43





Use document.ready(function(){...}).

– connexo
Nov 16 '18 at 7:43













Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

– diesel94
Nov 16 '18 at 9:54





Great ! I added $(document).ready(()=>{ }) to my code and it works! Why does it need it? "$" is analog $(document).ready(()=>{ })

– diesel94
Nov 16 '18 at 9:54













Before, you were trying to access the DOM before it was fully parsed.

– connexo
Nov 16 '18 at 9:57





Before, you were trying to access the DOM before it was fully parsed.

– connexo
Nov 16 '18 at 9:57












1 Answer
1






active

oldest

votes


















2














Thanks, @connexo, for the answer:



$(document).ready(()=>{
let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});
})


Now works! Become clear that without this statement i have tried to get access to input tags while them were not load.






share|improve this answer


























  • Explain in your answer what went wrong and why that fixes the problem.

    – connexo
    Nov 16 '18 at 10:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333397%2fwebstorm-cant-catch-input-with-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Thanks, @connexo, for the answer:



$(document).ready(()=>{
let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});
})


Now works! Become clear that without this statement i have tried to get access to input tags while them were not load.






share|improve this answer


























  • Explain in your answer what went wrong and why that fixes the problem.

    – connexo
    Nov 16 '18 at 10:00
















2














Thanks, @connexo, for the answer:



$(document).ready(()=>{
let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});
})


Now works! Become clear that without this statement i have tried to get access to input tags while them were not load.






share|improve this answer


























  • Explain in your answer what went wrong and why that fixes the problem.

    – connexo
    Nov 16 '18 at 10:00














2












2








2







Thanks, @connexo, for the answer:



$(document).ready(()=>{
let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});
})


Now works! Become clear that without this statement i have tried to get access to input tags while them were not load.






share|improve this answer















Thanks, @connexo, for the answer:



$(document).ready(()=>{
let inputs = $('input[type=radio]');
console.log(inputs);
let next;
let intervals = setInterval(() => {
next = inputs.filter(":checked").next('input');
if (!next.length) next = inputs.first();
next.prop('checked', true);
}, 2000);

inputs.change(() => {
clearInterval(intervals);
intervals = setInterval(function() {
next = inputs.filter(":checked").next('input');
if (next.length) next.prop('checked', true);
else inputs.first().prop('checked', true);
}, 2000);
});
})


Now works! Become clear that without this statement i have tried to get access to input tags while them were not load.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 13:11

























answered Nov 16 '18 at 9:58









diesel94diesel94

648




648













  • Explain in your answer what went wrong and why that fixes the problem.

    – connexo
    Nov 16 '18 at 10:00



















  • Explain in your answer what went wrong and why that fixes the problem.

    – connexo
    Nov 16 '18 at 10:00

















Explain in your answer what went wrong and why that fixes the problem.

– connexo
Nov 16 '18 at 10:00





Explain in your answer what went wrong and why that fixes the problem.

– connexo
Nov 16 '18 at 10:00




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333397%2fwebstorm-cant-catch-input-with-jquery%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine