Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select the custom tag from button attribute

I have created a button element structure like below

<input 
      type="button" 
      class="btn btn-primary" 
      name="redirect" 
      value="<mycustomtag data-id=15>"
      title="<mycustomtag data-id=14>"
>

Now, whenever the DOM gets ready I'm trying to find out the custom element and trying to replace with string. But I'm not able to replace the custom element.

The snippets I have used to find is as below

jQuery("mycustomtag").each(function(){
    //process here
});

PS this works fine in the following case:

<div><mycustomtag data-id=20></div>
<h4><mycustomtag data-id=18></h4>
like image 468
aMoL Thite Avatar asked Jan 01 '26 21:01

aMoL Thite


1 Answers

your code

jQuery("mycustomtag")

will try to find tag named mycustomtag, and what i understand is you are trying to replace the input attributes right ?

try following

//if you want to get values
var value = $("#btnCustom").attr("value");
var title = $("#btnCustom").attr("title");
alert(value);
alert(title);

//if you want to set values
$("#btnCustom").attr("value","replacevalue");
$("#btnCustom").attr("title","replace value 2");
value = $("#btnCustom").attr("value");
title = $("#btnCustom").attr("title");
alert(value);
alert(title);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input 
      type="button" 
      class="btn btn-primary" 
      name="redirect" 
      value="<mycustomtag data-id=15>"
      title="<mycustomtag data-id=14>"
      id="btnCustom"
>
like image 100
Dhaval Pankhaniya Avatar answered Jan 03 '26 10:01

Dhaval Pankhaniya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!