Using jQuery, include the href attribute inside a list item (li) with a specific data-id

I want to include target="_blank" in the a tag with li data-id="232"

<li class="" data-id="232">
    <a href="new.html">
    New Page    
  </a>
</li>

by utilizing jQuery.

Answer №1

Utilize the .attr method along with this specific jQuery selector:

$('li[data-id="232"] a').attr('target', '_blank')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to execute code before a user navigates away from the page?

Every attempt I've made has failed. I am trying to execute some code before the user exits the page: window.onbeforeunload = function(){ alert(1); } window.addEventListener("beforeunload", function(e){ alert(2); }); window.addEve ...

Using AJAX and jQuery to refresh a specific div when a specific button is clicked

I have a function that uses AJAX to update votes when clicked. Here is the code: $(function() { $(".vote").click(function() { var id = $(this).attr("id"); var name = $(this).attr("name"); var dat ...

I can't figure out why this form isn't triggering the JS function. I'm attempting to create an autocomplete form field that connects to a MySQL database using a PHP script and AJAX

I am encountering an issue while trying to implement the .autocomplete() function from jQuery UI with a list of usernames fetched from a MySQL database using a PHP script. Strangely, it is not functioning as expected and no errors are being displayed in th ...

As soon as the page finishes loading, the Dofullscreen function should be called without

Below is the script code: <script type="text/javascript"> function ToggleFullScreen() { var isInFullScreen = (document.fullScreenElement && document.fullScreenElement !== null) || // alternative standard meth ...

What is the best way to access the next-auth session using getStaticPaths and getStaticProps in dynamic routing scenarios?

I am currently working on implementing dynamic routing in a NextJS application. I need to retrieve the token from next-auth in order to make axios requests to an API and fetch data from getReport and getReports (located in /reports.js). However, I am facin ...

Unable to change the background color of h1 tag in a ReactJS project

import React from 'react' export default function Home(){ return<div> <h1 className="bg-dark text-white p-3">Home Page</h1> </div> } I am attempting to modify the background color of the h1 tag in my Reac ...

Refine information by using checkboxes with the help of jQuery, MySQL,

How do I use PHP and jQuery to filter content with checkboxes? I'm getting a warning about an undefined index when I try to post the form via jQuery. Check out my JavaScript file: function filterContent(){ var all = $(".all").val(); $('input.al ...

Tip: Using jQuery to Wrap Characters Based on Count

Within my table, there is a specific cell in each row that contains exactly 13 characters. <td class="need-to-wrap">0123456789012</td> I am looking to wrap characters #10, 11 and 12 with a span element like so: <td class="need-to-wrap"> ...

Retrieve information from a template and pass it to a Vue component instance

Being a newcomer to vue, I have a fundamental question. In my template, I have a value coming from a parsed object prop like this: <h1>{{myval.theme}}</h1> The above code displays the value in the browser. However, I want to store this value i ...

Check if a Vue 3 component has been loaded and if not, load a general component

Currently in the process of migrating a project from Vue 2 to Vue 3, I find myself searching for a way to determine if a component is loaded, and if not, how to load a GenericComponent as a placeholder. In Vue 2, I was able to accomplish this task using ...

The absence of Gapi definition in a React application hinders access to the Google Sheets API

Trying to send data from an HTML Form in a React.js web app to a google sheet. The script tag has been added in index.html (tried in <head> and in <body>) but gapi remains undefined. <body> <noscript>You need to enable JavaScript ...

Increase the border at the bottom while hovering with React.js and the Material UI library

Can someone help me achieve a hover effect similar to the one in this question on Stack Overflow: Hover effect : expand bottom border I am attempting to create the same effect in React using makeStyles of Material UI. Here is my current code: const useSty ...

What is holding Firestore back from advancing while Firebase Realtime Database continues to evolve?

I am currently working on a chat application using Firebase within my Vue.js project. In this setup, I need to display the user's status as either active or inactive. To achieve this, I implemented the solution provided by Firebase at https://firebase ...

Locating a specific class element within a collection of buttons using JQuery

I am currently working on making two buttons function similar to radio buttons, allowing only one to be selected at a time. HTML <button class="button" value="purchase" name="selector_button_group"> Purchase </button> <button class=" ...

What is the best way to animate a div sliding to the right, as if it is emerging from behind another div?

Alright, so I've got a div with multiple links in it. What I need is for all these links to trigger a sliding animation from the left side to the right within the same div. After my research, it seems like Jquery's animate function should be the ...

When utilizing customize-cra to modify antd less variables, it results in the generation of numerous redundant CSS files during the build

While utilizing customize-cra to override antd less variable, I have encountered an issue where it generates multiple duplicate CSS files during the build process. According to the documentation provided by antd, if I opt for the default import of CSS by ...

Enhancing Next.js SEO with 'use client' Metadata

Currently, I am facing an issue with my product page. The metadata for this page is fetched from the backend using an API that retrieves data from a database. To fetch this data and update it on the client side, I am utilizing a custom hook. However, the p ...

The search function on my blog is not displaying the blogs that have been filtered

I have encountered an issue with my code as I am unable to get any search results from the search bar. const RecentBlogs = ({recentBlogs}) => { const [query, setQuery] = useState("") const filteredItems = (() => { if(!query) return rec ...

When the add button is clicked, I would like to implement a feature where a checkbox is added

When the user clicks on the link "출력하기", I want the web page to add a checkbox to all images. I wrote this code, but it's not working. Can anyone help me? This is my JS: $(document).ready(function(){ $("#print").on('click', fu ...

I require an HTML <select multiple> element that includes a disabled option

Can anyone help me figure out how to create a multi-select box with a disabled element? I want the box to have the following options: All ----or---- option 1 option 2 I don't want the "----or----" option to be selectable. Here's the code I&a ...