Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call one Javascript function on different places in one amp HTML document using ID or Class? #32489

Open
danyal1248 opened this issue Feb 8, 2021 · 3 comments
Assignees
Labels
Stale Inactive for one year or more Type: Discussion/Question

Comments

@danyal1248
Copy link

Call add to cart to perform action on this id

add

I want to append result in this amp script container or add any div in this container but script will remain same addToCart

<script id="addToCart" type="text/plain" target="amp-script"> let bottomSheetView = document.getElementById("bottomSheetView"); if(bottomSheetView) { bottomSheetView.addEventListener("click",createBottomSheet); } async function createBottomSheet() {enter code here let productId = JSON.parse(await AMP.getState('productId.id')); AMP.setState({bottomSheet:false}); console.log(productId); } </script> <script type="application/json"> { "id" : "" } </script>

Note : Conclusion is that I want to execute one function and parse id in this and show result on another div or something in replace

@kristoferbaxter
Copy link
Contributor

@morsssss This looks like a question about how you could execute something with AMP Script. Could you take a look and see if we have adequate answers in our documentation?

@morsssss
Copy link
Contributor

morsssss commented Feb 8, 2021

Hey @danyal1248 ! I can't entirely tell what you're trying to do from the partial code you provide. It does look like you want to make it so that when a user clicks one DOM element, you set a state variable to false.

If that's it, does this sample help?

If that's not enough, please feel free to ask for more detailed help on Stack Overflow - or to sign up for the AMP Slack channel, where AMP developers discuss questions like this.

@stale
Copy link

stale bot commented Aug 12, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale Inactive for one year or more Type: Discussion/Question
Projects
None yet
Development

No branches or pull requests

3 participants