logo
down
shadow

In JavaScript, how to update attributes with jQuery


In JavaScript, how to update attributes with jQuery

By : Roberto Webmaster
Date : November 21 2020, 11:01 PM
it helps some times , You have to use .data() to update the health value.
code :
var battleResult = $(".defender").data("health") - $(".hero_button").data("attack");
console.log("battleResult should be: "+battleResult );

$(".defender").data({
    "health":  battleResult
});


Share : facebook icon twitter icon
Update nested attributes in a JavaScript object

Update nested attributes in a JavaScript object


By : Roland Salim
Date : March 29 2020, 07:55 AM
hop of those help? There are two issues. First is that you keep using data inside the loop, which means you're trying to access the top level keys instead of the inner keys. Change target = data[parents[i]]; to
code :
target = target[parents[i]];
for(var i=0; i<parents.length-1; i++){
   target = target[parents[i]];
}
target[parents[i]] = 'hey';
Should CSS update when JavaScript changes element attributes?

Should CSS update when JavaScript changes element attributes?


By : A.K.
Date : March 29 2020, 07:55 AM
wish of those help I found what was wrong. Have a look at this jsFiddle: http://jsfiddle.net/6jht2/1/
I made your code usable in a fiddle. What you were doing is passing an DOM element to a function by using this in an onclick attribute:
code :
<button onclick="nameClick(this)" name="FullNameExact" style="height:20%;width:75%;top:5%;left:13%;margin-bottom:5%">FULL NAME EXACT</button>
jQuery update data attributes using Json syntax

jQuery update data attributes using Json syntax


By : user3703458
Date : March 29 2020, 07:55 AM
may help you . I'm trying to update only one option in data array: , it is probably giving you the data as a string try:
code :
$('body').on('click', 'a.status', function() {
    var $this = $(this);
    var data = $this.data("set");
    data.result = data.result == 3 ? 4 : 3;
    $this.data("set", JSON.stringify(data));


    console.log(data)

});
Update HTML attributes depending on the total <li> jQuery

Update HTML attributes depending on the total <li> jQuery


By : John Joe
Date : March 29 2020, 07:55 AM
Hope this helps I have a slider with items in a list that will vary depending on the page. , nth-child is 1-based, while index is 0-based.
Change to:
code :
$( "ul#list li:nth-child" + '(' + (index + 1) ...
var sliderList = $("ul#list li");

function updateDataNum(){
  $.each(sliderList, function( index, value ) {
    $( "ul#list li:nth-child" + '(' + (index + 1) + ')').attr("data-slide-to",index);
  });
}

updateDataNum();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="list">
  <li data-target="#video-slider" data-slide-to="">One</li>  
  <li data-target="#video-slider" data-slide-to="">Two</li>  
  <li data-target="#video-slider" data-slide-to="">Three</li> 
  <li data-target="#video-slider" data-slide-to="">Four</li>
</ul>
$("#list li").attr("data-slide-to", function(index) {
  return index;
});
var sliderList = $("#list li");

function updateDataNum() {
  $("#list li").attr("data-slide-to", function(index) {
    return index;
  });
}

updateDataNum();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="list">
  <li data-target="#video-slider" data-slide-to="">One</li>  
  <li data-target="#video-slider" data-slide-to="">Two</li>  
  <li data-target="#video-slider" data-slide-to="">Three</li> 
  <li data-target="#video-slider" data-slide-to="">Four</li>
</ul>
$("#list li").attr("data-slide-to", index => index);
var sliderList = $("#list li");

function updateDataNum() {
  $("#list li").attr("data-slide-to", index => index);
}

updateDataNum();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="list">
  <li data-target="#video-slider" data-slide-to="">One</li>  
  <li data-target="#video-slider" data-slide-to="">Two</li>  
  <li data-target="#video-slider" data-slide-to="">Three</li> 
  <li data-target="#video-slider" data-slide-to="">Four</li>
</ul>
How can I set an attributes (base on child attributes) in jQuery or JavaScript?

How can I set an attributes (base on child attributes) in jQuery or JavaScript?


By : Stefano
Date : March 29 2020, 07:55 AM
hope this fix your issue You can achieve what you want by executing the following jQuery script:
code :
$(".menu-item").hover(function(){
   //Take the src value from the inner img tag
   let srcValue = ($(this).find("img").attr("src"));
   //Set the data-src attribute of the inner anchor tag
   $(this).find("a").attr("data-src", srcValue);
});
Related Posts Related Posts :
  • Javascript normal Array value and Array value created by match function comparison
  • pass a value from javascript to html and codeigniter
  • how to perform div hover shows another div but both div's are different form?
  • Draw a buffer with subbuffers webgl
  • Call a function on click event in Angular 2
  • Object.assign getters and setters in constructor
  • Have to set Number of Threads, Ramp up Period and Loop count from an external properties file
  • Post data from javascript to php file using ajax doesn't work
  • How to access method in prototypal inheritance pattern?
  • Q: How do I make each div fade away individually?
  • JavaScript/jQuery: how to get HTML and display HTML, including tags
  • Controller not loading if javaScript containing controller code is added dynamically to HTML dom
  • TypeError while retriving prototype properties
  • Google Maps API: adding zip code boundaries
  • Validating date with current date using jquery
  • ComponentWillMount keeps being called repeately
  • Laravel URL Generator With Angular JS Varible
  • Post data to another php page using ajax
  • Progressbar behavior depending on checkboxes bootstrap + jquery
  • node.js/socket.io/express execution order
  • nested EJS tag. Not working
  • Service call in controller in AngularJs using ES6
  • Div that acts as file upload?
  • Load D3 Url With API key
  • Read data in JSON format asp.net View in MVC
  • How to make separate force layout render loop?
  • Download a JSON behind a login page with nightmare
  • Regex to scan for a specific number of a repeating character
  • Array push still using previous reference?
  • Javascript context.closePath() method does not appear
  • Javascript variable undefined even after defining in Express Js, mongo db
  • How to add hover effect to <table> using CKEditor?
  • Autocomplete List Fixed Position Browser Resize
  • RegEx trying to match anything but a certain pattern with chars from the pattern being allowed
  • Validating value in HTML number input with Konva
  • Is any class object serializable in javascript?
  • 'content-type': 'text/html' not accepted until server is killed
  • Vue js Ready function is not triggered
  • setInterval wont work if timing is too short
  • Do reserved words need to be quoted when set as property names of JavaScript objects?
  • How to specify (optional) default props with TypeScript for stateless, functional React components?
  • reactjs render array of objects into a list gives an error
  • Todo list takes 30 seconds to appear
  • Reformat JSON objects inside an array to show them in HTML
  • can not route with angularjs
  • Running a script in a site that copies all keys pressed while the page is open
  • Using jQuery to select div with class signed by ruby iteration
  • Using classList when element is set to display none
  • Ionic 2 Express call not responding to user update function
  • Include background-image url css in jquery string
  • How to optimize jQuery.getJSON() for geolocalisation
  • Vue 2.0 setting up routes - Do not use 'new' for side effects
  • JSON Data not appearing on marker in Google map
  • Why appendChild is not working with node type?
  • Javascript function results
  • Add multiple callback responses to array
  • Parsley's EXCLUDED not recognizing :last
  • Make javaScript (not JQuery!) "activate" on keypress a CSS button:active style
  • forEach for Uint8ClampedArray
  • How to sent results of request to client browser in node.js
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com