/    Sign up×
Community /Pin to ProfileBookmark

How to show a span using getElementByID?

I’m trying to show a span with a specific id but it does not seem to work like this.
What am I doing wrong?

This is my code:

“`
// PHP
$xclass = “cart-check:”. $row[‘ID’];

// HTML
<span
id=”<?php echo $xclass; ?>”
style=”display: none;”>
<i class=”fas fa-check”></i> Added!
</span>
<button
type=”button”
class=”btn btn-sm bg-teal”
onclick=”AddCartItem(<?php echo $row[‘ID’]; ?>,'<?php echo $xclass; ?>’)”
>
<i class=”fas fa-cart-plus”></i>
</button>

// JAVASCRIPT
function AddCartItem(ItemID, Xclass) {
jQuery.ajax({
url: “cart_handler.php”,
data: { ItemID },
type: “POST”,
success:function(data){
document.getElementById(Xclass).show(); // <— This line is not working
$(“#user-availability-statusx”).show();
$(“#user-availability-statusx”).html(data);
},
error:function (){}
});
}

“`

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumSep 20.2020 — show() is a jQuery function and needs a jQuery object as an input:

`$('.' + Xclass).show();</C><br/>
<C>
$('#' + Xclass).show();`


Not shure if Xclass is a class as the name is indication or an ID as your use of getElementById is indicating. Choose the appropriate option.
Copy linkTweet thisAlerts:
@siddhi_patelSep 21.2020 — Hello...

I Think Using Show() Function You can Show Span.

like

var span=getElementById(1).show();


and also show thet like below

$("#Span ID").show();
×

Success!

Help @uwrp spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...