Use Jquery in KO Js Magento 2Add new field in checkoutjQuery returning undefined for value in billing step on checkoutCheck for customer email address exists in checkoutOneStepCheckout - display subtotals of tax classJquery-Ui Autocomplete with KnockoutJs Magento 2Magento 2: Initialize calendar widget inside payment uiComponentMagento 2 Add new field to Magento_User admin formMagento 2.2.1: Add Custom Upload file attribute in CheckoutLogin form validation is working but other forms validation is not workingAdd custom jQuery code after checkout page load

What does 'script /dev/null' do?

Prime joint compound before latex paint?

Doomsday-clock for my fantasy planet

Check if two datetimes are between two others

Latin words with no plurals in English

What does "enim et" mean?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Calculate Levenshtein distance between two strings in Python

"listening to me about as much as you're listening to this pole here"

How can I add custom success page

Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore

Sort in WP_Query(), not filter? Is it possible?

Where to refill my bottle in India?

My colleague's body is amazing

Why do UK politicians seemingly ignore opinion polls on Brexit?

Why doesn't a const reference extend the life of a temporary object passed via a function?

Copycat chess is back

aging parents with no investments

Lied on resume at previous job

How many letters suffice to construct words with no repetition?

Why is making salt water prohibited on Shabbat?

Ideas for colorfully and clearly highlighting graph edges according to weights

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

What happens when a metallic dragon and a chromatic dragon mate?



Use Jquery in KO Js Magento 2


Add new field in checkoutjQuery returning undefined for value in billing step on checkoutCheck for customer email address exists in checkoutOneStepCheckout - display subtotals of tax classJquery-Ui Autocomplete with KnockoutJs Magento 2Magento 2: Initialize calendar widget inside payment uiComponentMagento 2 Add new field to Magento_User admin formMagento 2.2.1: Add Custom Upload file attribute in CheckoutLogin form validation is working but other forms validation is not workingAdd custom jQuery code after checkout page load






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















On checkout page i want to hide summary component by default. and when a user clicks on a button i to show that Summary section. The Summary section is build through XML and KO. My Question is, Can i use Jquery in KO?



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);


$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);



);


HTML:



<div class="container checkout-acc-container checkout-acc-container-2 ">
<div class="row">
<div class="col-12 col-sm-12 col-md-8 col-lg-6 mr-auto ml-auto offset-lg-3">
<h2>Checkout</h2>
<div class="acc-fields-sec" data-bind="i18n: stepTitle" data-role="title">
<label>Email Address</label>
<input type="text" name="email" class="field input-acc-field email-field">
<p class="already-reg-text">This email is already registered with us, please sign in below</p>

<label class="field-label password-label">Password</label>
<input type="password" name="password" class="field input-acc-field password-field">
<p class="checkout-btn-sec">

<a href="#" class="checkout-btn"><!-- ko i18n: 'Next'--><!-- /ko --></a>
</p>
<p class="or-with-fb-text">OR sign in with Facebook</p>
<p class="fb-btn-sec">
<a href="#" class="fb-btn"><i class="fa fa-facebook"></i>SIGN IN WITH FACEBOOK</a>
</p>
</div>
</div>
</div>




at the last i have pasted my jQuery Code. But it is not working.Any idea how i could be?










share|improve this question



















  • 1





    NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

    – Prathap Gunasekaran
    Apr 5 at 7:12











  • can you please add this example in my code and repost it.

    – i_ali55
    Apr 5 at 7:15

















1















On checkout page i want to hide summary component by default. and when a user clicks on a button i to show that Summary section. The Summary section is build through XML and KO. My Question is, Can i use Jquery in KO?



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);


$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);



);


HTML:



<div class="container checkout-acc-container checkout-acc-container-2 ">
<div class="row">
<div class="col-12 col-sm-12 col-md-8 col-lg-6 mr-auto ml-auto offset-lg-3">
<h2>Checkout</h2>
<div class="acc-fields-sec" data-bind="i18n: stepTitle" data-role="title">
<label>Email Address</label>
<input type="text" name="email" class="field input-acc-field email-field">
<p class="already-reg-text">This email is already registered with us, please sign in below</p>

<label class="field-label password-label">Password</label>
<input type="password" name="password" class="field input-acc-field password-field">
<p class="checkout-btn-sec">

<a href="#" class="checkout-btn"><!-- ko i18n: 'Next'--><!-- /ko --></a>
</p>
<p class="or-with-fb-text">OR sign in with Facebook</p>
<p class="fb-btn-sec">
<a href="#" class="fb-btn"><i class="fa fa-facebook"></i>SIGN IN WITH FACEBOOK</a>
</p>
</div>
</div>
</div>




at the last i have pasted my jQuery Code. But it is not working.Any idea how i could be?










share|improve this question



















  • 1





    NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

    – Prathap Gunasekaran
    Apr 5 at 7:12











  • can you please add this example in my code and repost it.

    – i_ali55
    Apr 5 at 7:15













1












1








1


1






On checkout page i want to hide summary component by default. and when a user clicks on a button i to show that Summary section. The Summary section is build through XML and KO. My Question is, Can i use Jquery in KO?



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);


$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);



);


HTML:



<div class="container checkout-acc-container checkout-acc-container-2 ">
<div class="row">
<div class="col-12 col-sm-12 col-md-8 col-lg-6 mr-auto ml-auto offset-lg-3">
<h2>Checkout</h2>
<div class="acc-fields-sec" data-bind="i18n: stepTitle" data-role="title">
<label>Email Address</label>
<input type="text" name="email" class="field input-acc-field email-field">
<p class="already-reg-text">This email is already registered with us, please sign in below</p>

<label class="field-label password-label">Password</label>
<input type="password" name="password" class="field input-acc-field password-field">
<p class="checkout-btn-sec">

<a href="#" class="checkout-btn"><!-- ko i18n: 'Next'--><!-- /ko --></a>
</p>
<p class="or-with-fb-text">OR sign in with Facebook</p>
<p class="fb-btn-sec">
<a href="#" class="fb-btn"><i class="fa fa-facebook"></i>SIGN IN WITH FACEBOOK</a>
</p>
</div>
</div>
</div>




at the last i have pasted my jQuery Code. But it is not working.Any idea how i could be?










share|improve this question
















On checkout page i want to hide summary component by default. and when a user clicks on a button i to show that Summary section. The Summary section is build through XML and KO. My Question is, Can i use Jquery in KO?



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);


$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);



);


HTML:



<div class="container checkout-acc-container checkout-acc-container-2 ">
<div class="row">
<div class="col-12 col-sm-12 col-md-8 col-lg-6 mr-auto ml-auto offset-lg-3">
<h2>Checkout</h2>
<div class="acc-fields-sec" data-bind="i18n: stepTitle" data-role="title">
<label>Email Address</label>
<input type="text" name="email" class="field input-acc-field email-field">
<p class="already-reg-text">This email is already registered with us, please sign in below</p>

<label class="field-label password-label">Password</label>
<input type="password" name="password" class="field input-acc-field password-field">
<p class="checkout-btn-sec">

<a href="#" class="checkout-btn"><!-- ko i18n: 'Next'--><!-- /ko --></a>
</p>
<p class="or-with-fb-text">OR sign in with Facebook</p>
<p class="fb-btn-sec">
<a href="#" class="fb-btn"><i class="fa fa-facebook"></i>SIGN IN WITH FACEBOOK</a>
</p>
</div>
</div>
</div>




at the last i have pasted my jQuery Code. But it is not working.Any idea how i could be?







magento2 checkout knockoutjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 13 hours ago









magefms

2,5402426




2,5402426










asked Apr 5 at 6:57









i_ali55i_ali55

397112




397112







  • 1





    NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

    – Prathap Gunasekaran
    Apr 5 at 7:12











  • can you please add this example in my code and repost it.

    – i_ali55
    Apr 5 at 7:15












  • 1





    NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

    – Prathap Gunasekaran
    Apr 5 at 7:12











  • can you please add this example in my code and repost it.

    – i_ali55
    Apr 5 at 7:15







1




1





NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

– Prathap Gunasekaran
Apr 5 at 7:12





NO but you can add similar js into it then knockoutjs.com/documentation/visible-binding.html

– Prathap Gunasekaran
Apr 5 at 7:12













can you please add this example in my code and repost it.

– i_ali55
Apr 5 at 7:15





can you please add this example in my code and repost it.

– i_ali55
Apr 5 at 7:15










2 Answers
2






active

oldest

votes


















1














You can write your jQuery in initialize function. However, I would not recommend writing jQuery in your viewModal as it creates coupling between your viewModal and DOM elements. Your final code would be something like following ;



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);






share|improve this answer























  • let me try this. if you dont recommend then can you share same this in KO Js?

    – i_ali55
    13 hours ago











  • Please share your html template if you want the same in KO.

    – Vivek Kumar
    13 hours ago











  • added in question. please check.

    – i_ali55
    13 hours ago











  • Is the current jquery code I've provided working ?

    – Vivek Kumar
    12 hours ago











  • no, it is not working. prntscr.com/n8zvok

    – i_ali55
    11 hours ago


















1














You can try using jQuery function instead of $()

Examine this:



jQuery(".checkout-btn").click(function()
console.log("Hello World");
jQuery(".order-summary-sec").css("display","block");
);


Can you try this:



<script>
require([
'jquery'
], function(jQuery)
jQuery(".checkout-btn").click(function ()
console.log("Hello World");
jQuery(".order-summary-sec").css("display", "block");
);
);
</script>





share|improve this answer

























  • not working at all.

    – i_ali55
    10 hours ago











  • I think you can go with injecting jQuery directly to your html

    – magefms
    10 hours ago











  • It is not the standard way but I think it is the easiest way to make it work.

    – magefms
    10 hours ago











  • i tried that, but in html the jquery never worked.

    – i_ali55
    10 hours ago











  • can you show me how you did it?

    – magefms
    10 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2fmagento.stackexchange.com%2fquestions%2f268866%2fuse-jquery-in-ko-js-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can write your jQuery in initialize function. However, I would not recommend writing jQuery in your viewModal as it creates coupling between your viewModal and DOM elements. Your final code would be something like following ;



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);






share|improve this answer























  • let me try this. if you dont recommend then can you share same this in KO Js?

    – i_ali55
    13 hours ago











  • Please share your html template if you want the same in KO.

    – Vivek Kumar
    13 hours ago











  • added in question. please check.

    – i_ali55
    13 hours ago











  • Is the current jquery code I've provided working ?

    – Vivek Kumar
    12 hours ago











  • no, it is not working. prntscr.com/n8zvok

    – i_ali55
    11 hours ago















1














You can write your jQuery in initialize function. However, I would not recommend writing jQuery in your viewModal as it creates coupling between your viewModal and DOM elements. Your final code would be something like following ;



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);






share|improve this answer























  • let me try this. if you dont recommend then can you share same this in KO Js?

    – i_ali55
    13 hours ago











  • Please share your html template if you want the same in KO.

    – Vivek Kumar
    13 hours ago











  • added in question. please check.

    – i_ali55
    13 hours ago











  • Is the current jquery code I've provided working ?

    – Vivek Kumar
    12 hours ago











  • no, it is not working. prntscr.com/n8zvok

    – i_ali55
    11 hours ago













1












1








1







You can write your jQuery in initialize function. However, I would not recommend writing jQuery in your viewModal as it creates coupling between your viewModal and DOM elements. Your final code would be something like following ;



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);






share|improve this answer













You can write your jQuery in initialize function. However, I would not recommend writing jQuery in your viewModal as it creates coupling between your viewModal and DOM elements. Your final code would be something like following ;



define(
[
'ko',
'uiComponent',
'underscore',
'Magento_Checkout/js/model/step-navigator',
'Magento_Customer/js/model/customer',
'jquery'
],
function (
ko,
Component,
_,
stepNavigator,
customer,
$
)
'use strict';
/**
* check-login - is the name of the component's .html template
*/
return Component.extend(
defaults:
template: 'Magento_Checkout/check-login'
,

//add here your logic to display step,
isVisible: ko.observable(true),
isLogedIn: customer.isLoggedIn(),
//step code will be used as step content id in the component template
stepCode: 'isLogedCheck',
//step title value
stepTitle: 'Login',

/**
*
* @returns *
*/
initialize: function ()
this._super();
// register your step
stepNavigator.registerStep(
this.stepCode,
//step alias
null,
this.stepTitle,
//observable property with logic when display step or hide step
this.isVisible,

_.bind(this.navigate, this),

/**
* sort order value
* 'sort order value' < 10: step displays before shipping step;
* 10 < 'sort order value' < 20 : step displays between shipping and payment step
* 'sort order value' > 20 : step displays after payment step
*/
9
);

$(".checkout-btn").click(function()
console.log("Hello World");
$(".order-summary-sec").css("display","block");
);

return this;
,

/**
* The navigate() method is responsible for navigation between checkout step
* during checkout. You can add custom logic, for example some conditions
* for switching to your custom step
*/
navigate: function ()

,

/**
* @returns void
*/
navigateToNextStep: function ()
stepNavigator.next();


);







share|improve this answer












share|improve this answer



share|improve this answer










answered 13 hours ago









Vivek KumarVivek Kumar

2,5872729




2,5872729












  • let me try this. if you dont recommend then can you share same this in KO Js?

    – i_ali55
    13 hours ago











  • Please share your html template if you want the same in KO.

    – Vivek Kumar
    13 hours ago











  • added in question. please check.

    – i_ali55
    13 hours ago











  • Is the current jquery code I've provided working ?

    – Vivek Kumar
    12 hours ago











  • no, it is not working. prntscr.com/n8zvok

    – i_ali55
    11 hours ago

















  • let me try this. if you dont recommend then can you share same this in KO Js?

    – i_ali55
    13 hours ago











  • Please share your html template if you want the same in KO.

    – Vivek Kumar
    13 hours ago











  • added in question. please check.

    – i_ali55
    13 hours ago











  • Is the current jquery code I've provided working ?

    – Vivek Kumar
    12 hours ago











  • no, it is not working. prntscr.com/n8zvok

    – i_ali55
    11 hours ago
















let me try this. if you dont recommend then can you share same this in KO Js?

– i_ali55
13 hours ago





let me try this. if you dont recommend then can you share same this in KO Js?

– i_ali55
13 hours ago













Please share your html template if you want the same in KO.

– Vivek Kumar
13 hours ago





Please share your html template if you want the same in KO.

– Vivek Kumar
13 hours ago













added in question. please check.

– i_ali55
13 hours ago





added in question. please check.

– i_ali55
13 hours ago













Is the current jquery code I've provided working ?

– Vivek Kumar
12 hours ago





Is the current jquery code I've provided working ?

– Vivek Kumar
12 hours ago













no, it is not working. prntscr.com/n8zvok

– i_ali55
11 hours ago





no, it is not working. prntscr.com/n8zvok

– i_ali55
11 hours ago













1














You can try using jQuery function instead of $()

Examine this:



jQuery(".checkout-btn").click(function()
console.log("Hello World");
jQuery(".order-summary-sec").css("display","block");
);


Can you try this:



<script>
require([
'jquery'
], function(jQuery)
jQuery(".checkout-btn").click(function ()
console.log("Hello World");
jQuery(".order-summary-sec").css("display", "block");
);
);
</script>





share|improve this answer

























  • not working at all.

    – i_ali55
    10 hours ago











  • I think you can go with injecting jQuery directly to your html

    – magefms
    10 hours ago











  • It is not the standard way but I think it is the easiest way to make it work.

    – magefms
    10 hours ago











  • i tried that, but in html the jquery never worked.

    – i_ali55
    10 hours ago











  • can you show me how you did it?

    – magefms
    10 hours ago















1














You can try using jQuery function instead of $()

Examine this:



jQuery(".checkout-btn").click(function()
console.log("Hello World");
jQuery(".order-summary-sec").css("display","block");
);


Can you try this:



<script>
require([
'jquery'
], function(jQuery)
jQuery(".checkout-btn").click(function ()
console.log("Hello World");
jQuery(".order-summary-sec").css("display", "block");
);
);
</script>





share|improve this answer

























  • not working at all.

    – i_ali55
    10 hours ago











  • I think you can go with injecting jQuery directly to your html

    – magefms
    10 hours ago











  • It is not the standard way but I think it is the easiest way to make it work.

    – magefms
    10 hours ago











  • i tried that, but in html the jquery never worked.

    – i_ali55
    10 hours ago











  • can you show me how you did it?

    – magefms
    10 hours ago













1












1








1







You can try using jQuery function instead of $()

Examine this:



jQuery(".checkout-btn").click(function()
console.log("Hello World");
jQuery(".order-summary-sec").css("display","block");
);


Can you try this:



<script>
require([
'jquery'
], function(jQuery)
jQuery(".checkout-btn").click(function ()
console.log("Hello World");
jQuery(".order-summary-sec").css("display", "block");
);
);
</script>





share|improve this answer















You can try using jQuery function instead of $()

Examine this:



jQuery(".checkout-btn").click(function()
console.log("Hello World");
jQuery(".order-summary-sec").css("display","block");
);


Can you try this:



<script>
require([
'jquery'
], function(jQuery)
jQuery(".checkout-btn").click(function ()
console.log("Hello World");
jQuery(".order-summary-sec").css("display", "block");
);
);
</script>






share|improve this answer














share|improve this answer



share|improve this answer








edited 10 hours ago

























answered 12 hours ago









magefmsmagefms

2,5402426




2,5402426












  • not working at all.

    – i_ali55
    10 hours ago











  • I think you can go with injecting jQuery directly to your html

    – magefms
    10 hours ago











  • It is not the standard way but I think it is the easiest way to make it work.

    – magefms
    10 hours ago











  • i tried that, but in html the jquery never worked.

    – i_ali55
    10 hours ago











  • can you show me how you did it?

    – magefms
    10 hours ago

















  • not working at all.

    – i_ali55
    10 hours ago











  • I think you can go with injecting jQuery directly to your html

    – magefms
    10 hours ago











  • It is not the standard way but I think it is the easiest way to make it work.

    – magefms
    10 hours ago











  • i tried that, but in html the jquery never worked.

    – i_ali55
    10 hours ago











  • can you show me how you did it?

    – magefms
    10 hours ago
















not working at all.

– i_ali55
10 hours ago





not working at all.

– i_ali55
10 hours ago













I think you can go with injecting jQuery directly to your html

– magefms
10 hours ago





I think you can go with injecting jQuery directly to your html

– magefms
10 hours ago













It is not the standard way but I think it is the easiest way to make it work.

– magefms
10 hours ago





It is not the standard way but I think it is the easiest way to make it work.

– magefms
10 hours ago













i tried that, but in html the jquery never worked.

– i_ali55
10 hours ago





i tried that, but in html the jquery never worked.

– i_ali55
10 hours ago













can you show me how you did it?

– magefms
10 hours ago





can you show me how you did it?

– magefms
10 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • 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%2fmagento.stackexchange.com%2fquestions%2f268866%2fuse-jquery-in-ko-js-magento-2%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

Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

Magento2 - How to hide price filter only in specific categories?Multiselect price filter attribute in layered navigationhide only some categories from layered navigation in magentoRemove Price Filter on certain categoriescustomize layered price filter?Hide Price for a particular customer groupPrice filter in layered navigation not working correctly with price including tax in magento 2.2.3Magento 2 how to hide attribute at Layered navigation?Magento 2. how to hide price only for specific categoriesMagento 2 How can I hide the price and total from cart and checkout summary?Magento2: Can we add navigation layered filter like price filter for other attribute?