Custom HTML Element Attributes [Solved]

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
ccreeves
Posts: 7
Joined: Mon Jul 25, 2016 8:09 pm

Custom HTML Element Attributes [Solved]

Postby ccreeves » Mon Jul 25, 2016 8:37 pm

Hello,

First off, thanks so much for your work on this. Can't wait to play with it more.

Is it possible to set a custom attribute on a XAML element at design-time that persists in the output HTML?

For example, I would like to add the attribute "webkit-playsinline" to a MediaElement element so that it appears on the <video> element in the output HTML. Is this possible?

If not, I assume I could manually add this later via Javascript execution...but I notice neither "name" nor "id" attributes are set for html elements at runtime. So how would I go about modifying a specific HTML element?

Thanks,
Chris
Last edited by ccreeves on Tue Jul 26, 2016 7:26 pm, edited 1 time in total.

ccreeves
Posts: 7
Joined: Mon Jul 25, 2016 8:09 pm

Re: Custom HTML Element Attributes

Postby ccreeves » Mon Jul 25, 2016 9:44 pm

After further research, I think this is the approach I'd use for manually adding an attribute to a MediaElement (<video>), right?

Code: Select all

                object video = CSHTML5.Interop.GetDiv(MediaElementForVideo);
                CSHTML5.Interop.ExecuteJavaScript("$0.createAttribute('webkit-playsinline')", video);

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: Custom HTML Element Attributes

Postby JS-Support @Userware » Tue Jul 26, 2016 1:05 am

Hi,

Yes, this approach is the correct one.

Please note that the DOM produced by the MediaElement looks like this:

<div>
<video>
</div>

(you can see this by using the developer tools of your browser and inspecting the DOM tree)

Therefore, you should set the attribute on the child of the div, rather than the div itself, like this:

Code: Select all

object video = CSHTML5.Interop.GetDiv(MediaElementForVideo);
CSHTML5.Interop.ExecuteJavaScript("$0.firstChild.createAttribute('webkit-playsinline')", video);


Regards,
JS-Support

ccreeves
Posts: 7
Joined: Mon Jul 25, 2016 8:09 pm

Re: Custom HTML Element Attributes

Postby ccreeves » Tue Jul 26, 2016 7:24 pm

Makes sense, thanks so much for the reply. :)


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 44 guests

 

 

cron