• 0

JQuery not replacing text as it should


Question

Hi, here's my code:

HTML


<a href="" class="button off"><div class="button toggle">on</div><img src="https://icons.iconarchive.com/icons/artdesigner/urban-stories/128/House-icon.png" /><br />DOOR</a>
[/CODE]

JQuery code AFTER HTML (in <body> tags):

[CODE]<script>
$(".button").click(function () {
$(".toggle", this).text(($(".toggle", this).text() == "on") ? "off" : "on");
});</script>[/CODE]

what it should do?

- if button toggle <div> element is set to "on", set it to off. otherwise, set ti to on. :)

what it does?

- it shows the replacement but the text imediately jumps back to "on". :(((

I'm going crazy, clueless where's the catch???

Help me please :(

2 answers to this question

Recommended Posts

  • 0

You've got nested .buttons. It's probably causing some issues.

the callback inside your text() is looking for another nested .toggle inside "this", which is the Div.toggle. I'm sure it's getting itself in a twist.

Let me get a page running....

You might need to prevent the default.


<script>
$(".button").click(function (e) {
e.preventDefault();
$(".toggle", this).text(($(".toggle", this).text() == "on") ? "off" : "on");
});</script>
[/CODE]

edit : solution

This topic is now closed to further replies.
  • Posts

    • The Radeon RX 9060 XT is 5% slower than the GeForce RTX 5060 Ti, but the GeForce RTX 5060 Ti is 23% more expensive, at least when comparing MSRPs.
    • I would love to see Musk's face! 🤣🤣🤣
    • I think each AI option has their ups and downs. For Copilot, I find it more personable in how it talks compared to GPT & Gemini. I also appreciate the open ended questions it often provides at the end of its responses to keep the conversation going.
    • Microsoft offers free access to AI video creation with Bing Video Creator by Pradeep Viswanathan Two years ago, Bing Image Creator became one of the first major online services that allowed users to create images from text using OpenAI’s DALL-E model. Today, Microsoft is introducing Bing Video Creator, powered by OpenAI’s Sora, allowing users to create videos with text prompts. Despite announcing Sora last year, OpenAI has not been able to expand its availability to millions of ChatGPT users due to huge AI infrastructure requirements. It is still only available to ChatGPT Pro subscription users, which costs about $200 per month. Recently, Google announced its Veo 3 video generation model, which performs significantly better than OpenAI’s Sora, to all Gemini paid subscribers, making video generation accessible to even Gemini Pro subscribers, which costs just $20 per month. Now, Microsoft is democratizing access to video generation models by making Bing Video Creator free for all Bing users. Bing Video Creator is rolling out today globally (excluding China and Russia) on the Bing Mobile App, and it will be coming soon to the Bing desktop experience within Copilot Search. Bing Video Creator users will have the ability to choose between Fast and Standard generation speeds. Each user will have 10 Fast creations; following that, users can redeem 100 Microsoft Rewards points for each Fast creation or continue with Standard creation speeds. Once you have downloaded the Bing mobile app, here’s how you can access the Video Creator feature: Open Video Creator within the Bing Mobile app by clicking on the menu in the bottom right corner and selecting “Video Creator.” Just type in a text description of the video you want to create in the prompt box. Once the prompt text is ready, just tap “Create.” Or you can also just type directly into the Bing mobile app search bar "Create a video of..." to create a video. You’ll receive a notification when your video is ready to view. If required, you can also download the video or share it via social media or email. You will also have the ability to copy a direct link to the video for easy sharing elsewhere. Microsoft will be storing the generated videos for up to 90 days in your account for easy access later. Microsoft noted that the Bing Video Creator videos are 5 seconds long and can be created only in 9:16 format for now. Microsoft will be adding the 16:9 format soon. When you are waiting for your video to be created, you can also queue up another two videos. Once one of the slots becomes available, you can add another one to the queue. When Bing Video Creator becomes available on desktop, you can visit Bing.com/create for both image and video creation needs.
  • Recent Achievements

    • Week One Done
      Nullun earned a badge
      Week One Done
    • First Post
      sultangris earned a badge
      First Post
    • Reacting Well
      sultangris earned a badge
      Reacting Well
    • First Post
      ClarkB earned a badge
      First Post
    • Week One Done
      Epaminombas earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      150
    2. 2
      ATLien_0
      122
    3. 3
      Xenon
      121
    4. 4
      snowy owl
      99
    5. 5
      +Edouard
      94
  • Tell a friend

    Love Neowin? Tell a friend!