0

Actually i'm trying to change a class with jquery to a bootstrap badge item. The item's are generated dynamically so on click of the table item i add to a variable the id of the anchor.

Then i've made 4 functions for each item of popover that you can see on the screen enter image description here

Each of the popover anchors as CHIUSO RISOLTO etc. should change the main anchor class of the table item.

Actually i was trying to use something like this to change the class

function Risolt() {
    $("#idticket").removeClass();
    $('#idticket').addClass('badge badge-success');
}

I think the problem is on setting the id as onClick of table items i've set the following function

var idticket
function setId(id) {
    idticket = id
}
5
  • what class you want to remove put it as parameter of removeClass() Commented Feb 4, 2019 at 8:25
  • @JohnKarry can you please add some more code? Commented Feb 4, 2019 at 8:29
  • @MaheerAli actually i think the problem is the id as if i set the id manually it's works, added the code where i assign the id to the variable Commented Feb 4, 2019 at 8:30
  • @JohnKarry can you add whole code its confusing. please add html with id so i can give you exact solution Commented Feb 4, 2019 at 8:31
  • @jigarhalani solved i just had to concatenate the idticket and don't use it like text Commented Feb 4, 2019 at 8:33

3 Answers 3

1

SOLVED:

As i was setting of table item click the id to a variable the #idticket simply doesn't exist i just had to concatenate the variable in jquery and not add that as text.

Thank's all for helping.

Sign up to request clarification or add additional context in comments.

2 Comments

That description of the problem makes very little sense given the lack of context in the question. However as it sounds like it was a typographical error unique to your code I'd suggest simply deleting this question as it's unlikely to help any future visitors.
@RoryMcCrossan actually i'm unable to delete it cause of other answers
0

At first you should replace $("#idticket").removeClass(); to $("#idticket").removeAttr('class');, then add any class you want.

1 Comment

Calling removeClass() without arguments is the correct way to remove all classes on an element. removeAttr() is not required, nor is it good practice in this case.
0

You can use toggleClass jQuery to switch classes

$('#idticket').toggleClass("oldClass newClass");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.